65 commonly used regular expressions

First, the check digit of expression

1. Digital: ^ [0-9] * $ 
2.n-bit number: ^ \ n {D} $ 
3. least bit number n: ^ \ D {n,} $ 
4.mn digits: ^ \ d {m, n} $ 
digital 5. zero and non-zero at the beginning: ^ (0 | [1-9] [0-9] *) $ 
with up to two decimals 6. nonzero beginning: ^ (. [0-9] {1,2})? ([1-9] [0-9] *) + $ 
7 decimals with 1-2 positive or negative: ^ (\ - | \ + ?.) \ D + (\ \ D {1,2}) $? 
8. The positive, negative, and decimals:?.? ^ (\ - | \ +) \ D + (\ \ + D) $ 
9. The two a positive real number of decimal places: (. [0-9] {2})? ^ [0-9] + $ 
10 has a positive real number bits 1-3 decimal: ^ [0-9] + ([0-. 9] {1,3}) $? 
a positive non-zero integer 11: ^ [1-9] \ d * $ or ^ ([1-9] [0-9] *) or $ {1,3} ^ \ + [1-9] [0-9] * $? 
negative non-zero integer 12: ^ - [1-9] \ d * | 0 $ or ^ ((- \ d +) | (0+) ) $ 
13 non-negative integer: ^ \ d + $ or ^ [1-9] \ D * | $ 0 
14. A non-positive integer: ^ - [1-9] \ d * | 0 $ ^ or ((- \ + d) | (0 +)) $ 
15. The non-negative floating-point numbers: ^ \ d + (\ \ d +) $ or ^ [1-9] \ d * \ \ d * | 0 \ \ d * [.?.. ?. 1-9] \ d * | 0 \ 0+ | 0 $ 
16. The non-positive float:.?. ^ ((- \ d + (\ \ d +)) | (0 + (\ 0+))? ) or $ ^ (([0-9] + \ [0-9] * [1-9] [0-9] *.) | ([0-9] * [1-9] [0-9] * \ [0-9] +) | . ([0-9] * [1-9] [0-9] *)) $
17. The positive float: ^ [1-9] \ d * \ \ d * | 0 \ \ d * [1-9] \ d * + $ or ^ (([0-9] + \ [... 0-9] * [1-9] [0-9 ] *) | ([0-9] * [1-9] [0-9] * \ [0-9] +) |. ([0- 9] * [1-9] [0-9] *)) $ 
18 negative float: ^ [1-9] \ d * \ \ d * | 0 \ \ d * [1-9] \.. or d * + $ ^ (([0-9] + \ [0-9] * [1-9] [0-9] *) |. ([0-9] * [1-9] [0- . 9] * \ [0-9] +) | ([0-9] * [1-9] [0-9] *)) $ ( 
? 19. The floating-point numbers: ^ (- \ d +) (\. ??.. \ d +) $ or ^ - ([1-9] \ d * \ \ d * | 0 \ \ d * [1-9] \ d * | 0 \ 0+ | 0) $?.

 Second, check character expression

1. Characters: ^ [\ u4e00- \ u9fa5] {0,} $ 
2. alphanumeric: ^ [A-Za-z0-9 ] + $ or ^ [A-Za-z0-9] {4,40 } $ 
all characters 3. the length of 3 to 20: 3, 20 ^ {} $ 
4 by a string consisting of letters 26: ^ [a-Za-Z] + $ 
5. the 26 capital letters of string consisting of: ^ [AZ] + $ 
6. the letters written by a small string consisting of 26: ^ [AZ] + $ 
7. the string of numbers and English letters 26: ^ [a-Za- Z0-9] + $ 
8. the string of digits, letters or underscore 26 consisting of: ^ \ w + $ or ^ \ {W} $ 3,20 
9. the Chinese, English, numbers underlined comprising: ^ [\ u4E00 - \ _ u9FA5A-Za-Z0-9] + $ 
10. The Chinese, English, numbers, symbols such as but not underlined: ^ [\ u4E00- \ u9FA5A- Za-z0-9] + $ or ^ [\ u4E00- \ u9FA5A Z0-9--za] {2,20} $ 
11. The input may contain% ^ & '?,; $ = \ "characters such as: [% ^ &',; $ = \ X22] +? 
12. The inhibit input the characters contained ~: [^ ~ \ 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-the Z-] +: // [^ \ S] * or ^ http: // (. [\ w-] + \) + [\ w-] + (/ [\ W -./?%&=]*)?$ 
4. phone number: ^ (13 [0-9] | 14 [5 | 7] | 15 [0 | 1 | 2 | 3 | 5 | 6 | . 7 |. 8 |. 9] | 18 is [0 |. 1 | 2 |. 3 |. 5 |. 6 |. 7 |. 8 |. 9]) \ {D} $. 8 
5. The telephone number ( "XXX-XXXXXXX", " XXXX-XXXXXXXX" , "XXX-XXXXXXXX", "XXXXXXX", "XXXXXXXX"):? ^ (\ (\ d {3, 4} -) | \ d {3.4} -) \ d {7, 8} $ 
6. domestic Calls number: \ {D}. 3 - \. 8 {D} | \. 4 {D} - \ {D}. 7 
7. The ID number: ^ \ D {15} | \ {D} $ 18 is 
8. The short ID number (numbers, letters ending X): ^ ([0-9]) {7,18} (x | X) $ or ^ \ d {8,18} | [ 0-9x] {8,18} | [? ? 0-9X] {8,18} $ 
9. The account number is legitimate (beginning with the letter, allowing 5-16 bytes to allow alphanumeric underlined): ^ [a-zA- Z] [a-zA-Z0-9_] {4,15} $ 
10. password (start with a letter, a length between 6 and 18, can contain letters, numbers and underscores): ^ [a-zA- Z] \ w {5,17} $
11. A 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) (= (= * [az]?.)? . * [AZ]) {8,10} $. 
12. the date format: ^ \. 4 {D} - \ D {1,2} - \ D {1,2} 
13. 12 months of the year (01 -09 and 12 is 1):? ^ (0 [1-9] | 1 [0-2]) $ 
14. a month is 31 days (1 to 31 and 01-09): ^ (0 [1 -? 9] | (1 | 2) [0-9]) | 30 | 31 $ 
15.xml file:? ^ ([a-zA -Z] + -) + [a-zA-Z0-9] + \\ . [X | X-] [m | m] [L | L] $ 
16. a Chinese character regular expression: [\ u4e00- \ u9fa5] 
17. a double-byte characters: [^ \ x00- \ xff] ( including including characters, can be used to calculate the length of the string (a double-byte character length meter 2, ASCII characters are counted 1)) 
18. the regular expression blank line: \ n \ s * \ r ( blank may be used to remove line) 
19. Tencent QQ: [1-9] [0-9] {4} 
20 China ZIP:?! [1-9] \ {D}. 5 (\ D) 
21.IP address: \ ... d + \ \ d + \ \ d + \ \ d + ( extraction of useful IP address) 
22.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/it-cuiyi/p/10956200.html