Re module commonly used regular expression to match

07.01 self-summary

Re module commonly used regular expression to match

First, the check digit of expression

1. Digital

^[0-9]\*$

Digital 2.n bits

^\d{n}$

3. The least number of bits n

^\d{n,}$

Bit digital 4.mn

^\d{m,n}$

5. The number at the beginning of zero and non-zero

^(0|[1-9][0-9]\*)$

With up to two decimals 6. The non-zero at the beginning of

^([1-9][0-9]\*)+(\.[0-9]{1,2})?$

7. 1-2 with a positive or negative fractional

^(\-)?\d+(\.\d{1,2})$

8. The positive and negative numbers, decimals, and

^(\-|\+)?\d+(\.\d+)?$

9. There are two positive real number of decimal places

^[0-9]+(\.[0-9]{2})?$

1 to 10. The three positive real number decimal

^[0-9]+(\.[0-9]{1,3})?$

11. The non-zero positive integer

^[1-9]\d\*$ 或 ^([1-9][0-9]\*){1,3}$ 或 ^\+?[1-9][0-9]\*$

12. The non-zero negative integer

^\-[1-9][]0-9"\*$ 或 ^-[1-9]\d\*$

13. A non-negative integer

^\d+$ 或 ^[1-9]\d\*|0$

14. The non-positive integer

^-[1-9]\d\*|0$ 或 ^((-\d+)|(0+))$

15. Non-negative float

^\d+(\.\d+)?$ 或 ^[1-9]\d\*\.\d\*|0\.\d\*[1-9]\d\*|0?\.0+|0$

16. Non-positive float

^((-\d+(\.\d+)?)|(0+(\.0+)?))$ 或 ^(-([1-9]\d\*\.\d\*|0\.\d\*[1-9]\d\*))|0?\.0+|0$

17. positive 浮点 number

^[1-9]\d\*\.\d\*|0\.\d\*[1-9]\d\*$ 或 ^(([0-9]+\.[0-9]\*[1-9][0-9]\*)|([0-9]\*[1-9][0-9]\*\.[0-9]+)|([0-9]\*[1-9][0-9]\*))$

18. 负浮 score

^-([1-9]\d\*\.\d\*|0\.\d\*[1-9]\d\*)$ 或 ^(-(([0-9]+\.[0-9]\*[1-9][0-9]\*)|([0-9]\*[1-9][0-9]\*\.[0-9]+)|([0-9]\*[1-9][0-9]\*)))$

19. Float

^(-?\d+)(\.\d+)?$ 或 ^-?([1-9]\d\*\.\d\*|0\.\d\*[1-9]\d\*|0?\.0+|0)$

Second, check character expression

1. Chinese characters

^[\u4e00-\u9fa5]{0,}$

2. English and digital

^[A-Za-z0-9]+$ 或 ^[A-Za-z0-9]{4,40}$

3. length is 3-20 all characters

^.{3,20}$

4. The string consists of the 26 English letters

^[A-Za-z]+$

The string consists of 26 English capital letters

^[A-Z]+$

6. Write letters composed by the 26 small string

^[a-z]+$

7. The string of numbers and English letters 26

^[A-Za-z0-9]+$

8. The string of digits, letters or underscore 26 composed of

^\w+$ 或 ^\w{3,20}$

9. Chinese, English, numbers, including underscore

^[\u4E00-\u9FA5A-Za-z0-9_]+$

10. Chinese, English, numbers, symbols excluding underline

^[\u4E00-\u9FA5A-Za-z0-9]+$ 或 ^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$

11. The character input containing ~ of prohibits

[^~\x22]+

Third, the special needs of expression

1.Email address

^\w+([-+.]\w+)\*@\w+([-.]\w+)\*\.\w+([-.]\w+)\*$

2. Domain Name

[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?

3.InternetURL

[a-zA-z]+://[^\s]\* 或 ^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]\*)?$

4. Number

1. phone number

^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$

2. Domestic phone number (0511-4405222,021-87888822)

\d{3}-\d{8}|\d{4}-\d{7}

3. The phone number regular expression (support phone number, area code 3-4, 7-8 live numbers, 1-4 extension):

 ((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)

The ID number (15, 18 digits), the last digit is a check digit, X may be a number or character

(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)

6. username and password

1. The account is valid (beginning with the letter, allow 5-16 bytes, allows alphanumeric characters and underscores)

^[a-zA-Z][a-zA-Z0-9_]{4,15}$

2. Password (start with a letter, a length between 6 and 18, can contain letters, numbers and underscores)

^[a-zA-Z]\w{5,17}$

3. Strong Password (must contain a combination of uppercase and lowercase letters and numbers, special characters can not be used, a length of between 8-10)

^(?=.\*\d)(?=.\*[a-z])(?=.\*[A-Z])[a-zA-Z0-9]{8,10}$

4. Strong passwords (which must contain a combination of uppercase and lowercase letters and numbers, special characters may be used, a length of between 8-10)

^(?=.\*\d)(?=.\*[a-z])(?=.\*[A-Z]).{8,10}$

7. Time

1. Date Format

^\d{4}-\d{1,2}-\d{1,2}

2. year 12 months (01 ~ 09 and 1-12)

^(0?[1-9]|1[0-2])$

3. 31 days of the month (1 to 01 ~ 09 and 31)

^((0?[1-9])|((1|2)[0-9])|30|31)$

8.xml file

^([a-zA-Z]+-?)+[a-zA-Z0-9]+\\.[x|X][m|M][l|L]$

9. Chinese characters in regular expressions

[\u4e00-\u9fa5]

10. The positive expression blank line

\n\s\*\r (可以用来删除空白行)

11.HTML mark regular expressions

<(\S\*?)[^>]\*>.\*?|<.\*? /> ( 首尾空白字符的正则表达式^\s\*|\s\*$或(^\s\*)|(\s\*$) (可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式)

12. QQ number Tencent

[1-9][0-9]{4,} (腾讯QQ号从10000开始)

13. China Postal Code

[1-9]\d{5}(?!\d) (中国邮政编码为6位数字)

14.IP address

((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))

Guess you like

Origin www.cnblogs.com/pythonywy/p/11113349.html