Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Looking for examples of regular expressions in java?
Looking for examples of regular expressions in java?
First, check the expression of the number.

1 number: [0-9] * $

2 N-digit numbers: \ d {n} $

3 numbers with at least n digits: \ d {n,} $

4 m-n digits: \ d {m, n} $

Numbers starting with zero and nonzero: (0 | [1-9] [0-9] *) $

6 Number with at most two decimal places at the beginning of nonzero: ([1-9] [0-9] *)+ (. [0-9] { 1,2})? $

7 Positive or negative numbers with decimal places of 1-2: (\-)? \d+(\。 \d{ 1,2})? $

8 Positive number, negative number and decimal number: (\-| \+)? \d+(\。 \d+)? $

9 A positive real number with two decimal places: [0-9]+ (. [0-9] {2})? $

10 is a positive real number of 1~3 decimal places: [0-9]+ (. [0-9] { 1,3})? $

1 1 nonzero positive integer: [1-9] \ d * $ or ([1-9] [0-9] *) {1,3} $ or \+? [ 1-9][0-9]*$

12 nonzero negative integer: \-[ 1-9] [] 0-9 "* $ or -[ 1-9] \ d * $

13 non-negative integer: \ d+$ or [1-9] \ d * | 0 $.

14 is not a positive integer: -[ 1-9] \ d * | 0 $ or (-\ d+)|(0+)$

15 non-negative floating-point number: \ d+(\. \ d+)? $ or [1-9] \ d * \ \ d * | 0 \。 \ d * [ 1-9] \ d * | 0? \.0+|0$

16 non-positive floating point number: (-\ d+(\. \ d+)? )|(0+(\.0+)? )) or (-([ 1-9] \ d * \. \ d * | 0 \。 \ d *[ 1-9]\ d *)| 0? \.0+|0$

17 positive floating point number: [1-9] \ d * \. \ d * | 0 \。 \ d * [ 1-9] \ d * $ or (([0-9]+\。 [0

18 negative floating point number: -([ 1-9] \ d * \. \ d * | 0 \。 \ d * [1-9] \ d *) $ or (-((0-9)+)

19 floating point number: (-? \d+)(\。 \d+)? $ or-? ([ 1-9]\d*\。 \d*|0\。 \d*[ 1-9]\d*|0? \.0+|0)$

Second, check the expression of the characters.

1 Chinese character: [\ U4E00-\ U9FA5] {0,} $

2 English and numbers: [A-ZA-Z0-9]+$ or [A-ZA-Z0-9] {4,40} $

3 All characters with a length of 3-20:. {3,20} $

4 A string of 26 English letters: [a-za-z]+$

5 A string consisting of 26 uppercase English letters: [a-z]+$

6 A string consisting of 26 lowercase English letters: [a-z]+$

7 A string consisting of numbers and 26 English letters: [a-za-z0-9]+$

8 strings consisting of numbers, 26 English letters or underscores: \ w+$ or \ w {3 3,20} $.

9 Chinese, English and figures include underscores: [\ U4E00-\ U9FA5A-ZA-Z0-9 _]+$

10 Chinese, English, numbers, but excluding underscores and other symbols: [\ U4E00-\ U9FA5A-ZA-Z0-9]+$ or [\ U4E00-\ U9FA5A-ZA-Z0-9] {2,20} $

1 1 You can use%&',; =? $ \ "and other characters: [%&; ',; =? $\x22]+

12 input of characters containing ~: [~ \ x22]+ is prohibited.

Three. Expression of special needs

1 email: \ w+([-+] \ w+) * @ \ w+([-). ] \ w+) * \。 \ w+([-。 ] \ w+) * $

2 domain name: [a-za-z0-9] [-a-za-z0-9] {0,62} (/. [a-za-z0-9] {0,62})+/。

Internet address: [a-za-z]+:/[\ s] * or http://([\ w-]+\. )+[\ w-]+(/[\ w-。 /? % & amp=]*)? $

4 Mobile phone number: (13 [0-9] |14 [5 | 7] |15 [0 |1| 2 | 3 | 5 | 6 | 7 | 8 | 9] |/kloc-.

5. Telephone number ("XXX-XXXXXXXX", "XXX-xxxxxxxx", "XXX-XXXXXXXX", "XXX-xxxxxxxx", "xxxxxxxx", "xxxxxxxx"): (\ (\ d {3,4}-) | \ d {3.4}-) \d{7,8}$

6 domestic telephone numbers (05 1 1-4405222, 021-8788822): \ d {3}-\ d {8} | \ d {4}-\ d {7}

7 ID number:

15 or 18 ID card: \ d {15} | \ d {18} $

15 ID card: [1-9] \ d {7} ((0 \ d) | (1[0-2]) ([0 |1| 2] \ d) | 3 [

18 id card: [1-9] \ d {5} [1-9] \ d {3} ((0 \ d) | (1[0-2]) (([0 |)

8 Short ID number (number ending with the letter X): ([0-9]) {7, 18} (x | x)? $ or \ d {8, 18} | [0-9x] {8, 18} | [0-9x] {8, 18}? $

9 Whether the account is legal (5- 16 bytes are allowed at the beginning of the letter, and alphanumeric underline is allowed): [a-za-z] [a-za-z0-9 _] {4, 15} $

10 password (starting with a letter, the length is between 6 and 18, and it can only contain letters, numbers and underscores): [a-za-z] \ w {5, 17} $

1 1 strong password (must contain a combination of uppercase and lowercase letters and numbers, no special characters, and the length is between 8- 10): (? =.*\d)(? =.*[a-z])(? =.*[A-Z])。 {8, 10}$

12 date format: \ d {4}-\ d {1, 2}-\ d {1, 2}

In a year 13 12 months (0 1 ~ 09 and 1 ~ 12): (0? [ 1-9]| 1[0-2])$

One month 14 3 1 day (0 1 ~ 09 and 1 ~ 3 1): ((0? [ 1-9])|(( 1|2)[0-9])|30|3 1)$

15 currency input format:

16 1. We can accept four expressions of money: 10000.00 and 10000.00, and 10000 and/without points.

17 2. This means any number that does not start with 0, but it also means that a character "0" fails, so we adopt the following form: (0 | [1-9] [0-9] *) $

18 3.0 or a number that does not start with 0. We can also allow a negative sign at the beginning: (0 |-? [ 1-9][0-9]*)$

19 4. This means a 0 or a number that may be negative and does not start with 0. Let users start from 0. Also remove the negative sign, because money can't be negative forever. The following is the possible decimal part: [0-9]+ (. [0-9]+)? $

20 5. It must be noted that there must be at least 1 digit after the decimal point, so "10." Failed, but passed "10" and "10.2": [0-9]+(. [0-9].$

2 1 6. So we stipulate that there must be two digits after the decimal point. If you feel too harsh, you can do this: [0-9]+ (. [0-9] { 1,2})? $

This allows the user to write only one decimal place. Now, to consider the comma in the number, you can do this: [0-9] {1, 3} (,[0-9] {3}) * (. [0-9] { 1,2})? $

23 8. 1 to 3 numbers, followed by any comma +3 numbers. Comma is optional, but not required: ([0-9]+| [0-9] {1, 3} (,[0-9] {3}) *). [0 $

Note: This is the final result. Don't forget that "+"can be replaced by "*" if you think an empty string is acceptable (strange, why? Finally, don't forget to remove the backslash when using the function. Common mistakes are here.

25 xml file: ([a-za-z]+-? )+[a-zA-Z0-9]+\\。 [x|X][m|M][l|L]$

26 Regular expression of Chinese characters: [\u4e00-\u9fa5]

27 double-byte characters: [\ x00-\ xff] (including Chinese characters, which can be used to calculate the length of a string (the length of a double-byte character is 2 meters, and the ASCII character is 1)).

28 Blank Line Regular Expression: \n\s*\r (can be used to delete blank lines)

Regular expression of 29 HTML tags:

Regular expression of leading and trailing white space characters: \ s * | \ s * $ or (\ s *) | (\ s * $) (can be used to delete white space characters (including spaces, tabs, page breaks, etc.). At the beginning and end of a line, this is a very useful expression.

3 1 Tencent QQ number: [1-9][0-9]{4,} (Tencent QQ number starts from 10000)

Postal code of China: [1-9]\d{5} (? ! \d) (The postcode of China is 6 digits).

33 IP address: \d+\. \d+\。 \d+\。 \d+ (useful when extracting IP address)