Home Web Front-end JS Tutorial Some small exercises on regular expressions

Some small exercises on regular expressions

Mar 13, 2018 am 09:34 AM
several practise expression

这次给大家带来关于正则表达式的几个小练习,使用正则表达式的注意事项有哪些,下面就是实战案例,一起来看一下。

练习1:匹配abc

练习2:包含一个a~z,后面必须是0~9 -->[a-z][0-9]或者[a-z]\d
    * [a-z] : a~z
    * [0-9]/\d : 0~9

练习3:必须第一个是字母,第二个是数字 -->^[a-z][0-9]$
    * ^[a-z] : 表示首字母必须是a~z
    * \d{2,10} : 数字有2到10
    * [a-z]$ : 表示必须以a-z的字母结尾

练习4:必须第一个是字母,字母后面跟上4~9个数字

练习5:不能是数字0-9

    * [^0-9] : 不能是0~9练习6:QQ匹配:^[1-9]\d{4,11}$
都是数字5~12位
并且第一位不能是0练习7:手机号码匹配^1[3578]\d{9}$1.以13/15/17/182.长度是11
Copy after login

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

怎样添加带提示功能的代码块

常用的WebStorm快捷键


The above is the detailed content of Some small exercises on regular expressions. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to practice typing with Kingsoft Typing Guide - How to practice typing with Kingsoft Typing Guide How to practice typing with Kingsoft Typing Guide - How to practice typing with Kingsoft Typing Guide Mar 18, 2024 pm 04:25 PM

Nowadays, many friends like to use Kingsoft Typing Assistant, but the typing speed seriously affects work efficiency, so I teach you to practice typing speed. So how to use Kingsoft Typing Assistant to practice typing? Today, the editor will give you a tutorial on how to practice typing numbers with Kingsoft Typing Assistant. The following is described, I hope it will be helpful to everyone. First, open the Kingsoft typing software, then click the (Getting Started) button with your mouse, then click the (Number Keys) button in a new window, then click the (Start from Scratch) button below to practice, or click the (Test Mode) button. , just enter numbers for practice. In addition, Kingsoft Typing Assistant has other functions that can help you practice typing better. 1. Select practice mode: On the software interface, you can see that there are different practice modes, such as "New

How to practice Wubi typing for beginners - Wubi input method typing practice How to practice Wubi typing for beginners - Wubi input method typing practice Mar 18, 2024 pm 06:30 PM

Wubi typing, also known as Wubi input method, is an efficient Chinese character input method. For beginners, mastering Wubi typing requires a certain amount of time and patience. Below, the editor has compiled the learning methods for Wubi typing beginners. Let’s take a look! 1. Understand the principles of Wubi font Wubi font is a type of font based on Input method for strokes and radicals. Each Chinese character can be composed of different strokes and radicals. Therefore, the key to learning Wubi font is to understand the combination rules of strokes and root characters. In the five-stroke font, there are five basic strokes: horizontal, vertical, left, right, and fold. These basic strokes can be combined into different radicals, which in turn can be combined into complete Chinese characters. 2. Learn the radicals and key positions. In Wubi font, each letter key corresponds to one or more radicals. therefore

Regular expression exercises in Java Regular expression exercises in Java Jun 16, 2023 pm 02:36 PM

In Java, regular expressions are one of the most commonly used technologies and can be used in almost any text processing scenario, such as text search, extraction, analysis, replacement, etc. Its powerful matching capabilities can greatly improve development efficiency, while making the code more concise and easier to maintain. The following are some regular expression exercises in Java to help you master the application of regular expressions. Regular expression for matching Chinese characters: [u4e00-u9fa5] Explanation: The Unicode code value range of Chinese characters is from 4e00 to 9f

How to solve Python expression syntax errors? How to solve Python expression syntax errors? Jun 24, 2023 pm 05:04 PM

Python, as a high-level programming language, is easy to learn and use. Once you need to write a Python program, you will inevitably encounter syntax errors, and expression syntax errors are a common one. In this article, we will discuss how to resolve expression syntax errors in Python. Expression syntax errors are one of the most common errors in Python, and they are usually caused by incorrect usage of syntax or missing necessary components. In Python, expressions usually consist of numbers, strings, variables, and operators. most common

In C and C++, comma is used to separate expressions or statements In C and C++, comma is used to separate expressions or statements Sep 09, 2023 pm 05:33 PM

In C or C++, the comma "," has different uses. Here we will learn how to use them. Commas as operators. The comma operator is a binary operator that evaluates the first operand, discards the result, then evaluates the second operand and returns the value. The comma operator has the lowest precedence in C or C++. Example #include<stdio.h>intmain(){ intx=(50,60); inty=(func1(),func2());} Here 60 will be assigned to x. For the next statement, func1( will be executed first

Java Lambda Expression in Practice: Unlocking the Mysteries of Functional Programming with Code Java Lambda Expression in Practice: Unlocking the Mysteries of Functional Programming with Code Feb 26, 2024 am 10:25 AM

Lambda expression, as the name suggests, is an anonymous function with the arrow symbol (->) as its core. It allows you to pass blocks of code as arguments to other methods, or store them into variables for later use. Lambda expression syntax is concise and easy to understand, and it is very suitable for processing data flow and parallel computing. 1. The basic syntax of Lambda expression The basic syntax of Lambda expression is as follows: (parameter list)->{code block} Among them, the parameter list and code block are optional. If there is only one parameter, the parentheses can be omitted. If the code block is only one line, the curly braces can be omitted. For example, the following code block uses a Lambda expression to add 1 to a number: List

Introduction to exponential function expressions in C language Introduction to exponential function expressions in C language Feb 18, 2024 pm 01:11 PM

Introduction to how to write exponential function expressions in C language and code examples What is an exponential function? The exponential function is a common type of function in mathematics. It can be expressed in the form of f(x)=a^x, where a is the base and x is the exponent. . Exponential functions are mainly used to describe exponential growth or exponential decay. Code example of exponential function In C language, we can use the pow() function in the math library to calculate the exponential function. The following is a sample program: #include

lambda expression in Java lambda expression in Java Jun 09, 2023 am 10:17 AM

Lambda expressions in Java With the release of Java 8, lambda expressions have become one of the most concerned and discussed topics among Java developers. Lambda expressions can simplify Java programmers' tedious writing methods, and can also improve the readability and maintainability of programs. In this article, we will take a deep dive into lambda expressions in Java and how they provide a simpler and more intuitive programming experience in Java code.

See all articles