Home> Common Problem> body text

Regular expression does not contain

zbt
Release: 2023-07-05 10:50:56
Original
4295 people have browsed it

Regular expressions will be used by friends no matter what kind of development they are doing, but many people don’t understand regular expressions well, and they are too lazy to read them because they are used less frequently. When using them, Just go online and look for it, but often you search online for a long time, and the results may not necessarily match what you need.

Regular expression does not contain

Regular expressions will be used by friends no matter what kind of development they are doing, but many people don’t understand regular expressions well, and because of the frequency of use Because it is relatively low and I am too lazy to look at it, I just go online to look for it when I want to use it. However, I often search online for a long time, and the results may not necessarily match what I need.

Number regularity

1. Pure digital regularity: ^[0-9]*$

2. Numbers with n digits regularity: ^\d{n} $

3. Regular rules with at least n digits: ^\d{n,}$

4. Regular rules with digits between m-n digits: ^\d{m,n }$

5. Matching integers (does not distinguish between positive and negative numbers): ^-?[1-9]d*$

6. Matching negative integers: ^-[1-9] d*$

String regular expression

1, Pure English letter regular expression (not case-sensitive): ^[A-Za-z] $

2, Regular rules for pure English uppercase letters: ^[A-Z] $

3. Regular rules for pure English lowercase letters: ^[a-z] $

4. Regular rules for only numbers and 26 English letters: ^[A-Za-z0-9] $

5. The character length is between m-n characters: ^.{m,n}$

6. It starts with a letter, The length is between 6 and 18, and can only contain letters, numbers and underscores: ^[a-zA-Z]\w{5,17}$

7. It starts with a letter and has a length between 6 and 18. Between them, they can only contain letters and numbers without underscores: ^[a-zA-Z][a-zA-Z0-9]{4,15}$

8. They must and can only contain numbers. The regular expression of sum letters: ^(?![0-9] $)(?![a-zA-Z] $)[0-9A-Za-z]{6,10}$

with Let’s talk about this as an example

^ means the starting position of a line

(?![0-9] $) means not all numbers

(?![a- zA-Z] $) means it is not all letters

[0-9A-Za-z] {6,10} means it consists of 6-10 digits or letters

$ Matching lines The three conditions of the ending position

determine that this expression must contain numbers and letters, it can only contain numbers and letters, and the character length is between 6-10 digits.

9. ID number (only 15 or 18 digits are verified) regular: ^d{15}|d{18}$

Let’s explain the rules a little (you can follow the above Examples verify each other and enhance understanding)

\w: represents numbers, letters and underlines.

\d: Represents only numbers.

^: The starting position of the string. If it is inside [ ], it means "not", which means excluding the content contained in [ ]

^n: It means it must start with n string.

$: The end position of the string.

?=n: Indicates that the string n is followed immediately.

?!n: Indicates that the string n is not followed immediately.

The above is the detailed content of Regular expression does not contain. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Articles by Author
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!