Official account: Java Xiaokaxiu, website: Javaxks.com
Author: _asdflwlong links: zyc88.blog.csdn.net/article/details/98479629
One, the expression of the check number
- The Numbers:
^ [0-9] * $
- N digits:
^\d{n}$
- A number with at least n digits:
^\d{n,}$
- M-n digits:
^\d{m,n}$
- Numbers beginning with zero and non-zero:
^ (0 | [1-9] [0-9] *) $
- Non-zero numbers with at most two decimal digits:
^ ((1-9] [0-9] *) + (. [0-9] {1, 2})? $
- A positive or negative number with 1-2 decimal places:
^ (\)? \ d + (\ \ d {1, 2})? $
- Positive, negative, and decimal numbers:
^ (\ | \ +)? \d+(\.\d+)? $
- A positive real number with two decimal places:
^ [0-9] + (. [0-9] {2})? $
- A positive real number with 1 to 3 decimal places:
^ [0-9] + (. [0-9] {1, 3})? $
- Positive non-zero integers:
^[1-9]\d*$or ^([1-9][0-9]*){1,3}$or ^\+? [1-9] [0-9] * $
- Negative integers that are not zero:
^ \ [1-9] [] 0-9 "* $or ^ - [1-9] \ d * $
- Non-negative integers:
^ \ d + $or ^ 1-9] [\ | 0 $d *
- Non-positive integers:
^ - [1-9] \ d * | 0 $or ^ ((\ d +) | (0 +)) $
- Non-negative floating point numbers:
^\d+(\.\d+)? $or ^ [1-9] \ d * \ \ d * \ | 0. [1-9] \ d \ d * * | 0? \. | 0 0 + $
- Non-positive floating point numbers:
^((-\d+(\.\d+)?) | (0 + (\. 0 +)? ) $or ^ (- (1-9] [\ d * \ \ d * \ | 0. [1-9] \ d \ d * *)) | 0? \. | 0 0 + $
- Positive floating point numbers:
^ 1 - [9] \ d * \ \ d * \ | 0. 1-9] [\ \ d * d * $or ^ (([0-9] + \. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \ [0-9] +) | ([0-9] * [1-9] [0-9] *)) $
- Negative floating point:
^ - (1-9] [\ d * \ \ d * \ | 0. 1-9] [\ \ d * d *) $or ^ (- (([0-9] + \. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \ [0-9] +) | ([0-9] * [1-9] [0-9] *))) $
- Floating point Numbers:
^ (-? \d+)(\.\d+)? $or ^ -? ([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0? $\. | 0 + 0)
Second, the expression of the verification character
- Chinese characters:
^[\u4e00-\u9fa5]{0,}$
- English and Figures:
^ [A Za - z0-9] + $or ^ [A Za - z0-9] 40 {4} $
- All characters from 3 to 20:
^. {3, 20} $
- The value is a string of 26 letters:
^[A-Za-z]+$
- A string consisting of 26 uppercase English letters:
^[A-Z]+$
- A string consisting of 26 lowercase letters:
^[a-z]+$
- A string of 26 letters and numbers:
^[A-Za-z0-9]+$
- A string of 26 letters, digits, and underscores (_) :
+ $or ^ ^ \ w \ w {3, 20}
- Chinese, English and digits including underscores (_) :
^[\u4E00-\u9FA5A-Za-z0-9_]+$
- Chinese, English, numerals but not underscores:
^ [\ u4E00 - \ u9FA5A - Za - z0-9] + $or ^ [\ u4E00 - \ u9FA5A - Za - z0-9] {2, 20} $
- Can be typed with
& ^ % '; =? $\"
Characters such as:[^%&',;=?$\x22]+
- Do not enter characters containing ~
[^~\x22]+
Other:
.* matches any character except \n.
/ [\ u4E00 \ u9FA5] / characters
/[\uFF00-\uFFFF]/ full Angle symbol
/[\u0000-\u00FF]/ half corner symbol
Special requirements expression
- Email address:
^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
- Domain name:
[a - zA - Z0-9] [9] - a - zA - Z0 - on conversion {0} (/. [a zA - Z0-9] [9] - a - zA - Z0 - on conversion {0}) + /.?
- InternetURL:
[a zA - z] + : / / [^ \ s] * or ^ http:// ([-] \ w + \.) +[\w-]+(/[\w-./?%&=]*)? $
- Mobile 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}$
- Telephone number (“XXX-XXXXXXX”, “XXXX-XXXXXXXX”, “XXX-XXXXXXX”, “XXX-XXXXXXXX”, “XXXXXXX” and “XXXXXXXX “) :
^ (\ (\ d {3, 4} -) | \ d {} 3.4 -)? \ d {7, 8} $
- Domestic Telephone Number (0511-4405222, 021-87888822) :
\d{3}-\d{8}|\d{4}-\d{7}
- Id number (15 and 18 digits) :
^\d{15}|\d{18}$
- Short ID card number (ending with digit and letter X) :
^ ([0-9] {7} 16 (x | x)? $or ^ \ d {8} 16 | x [0-9] {8} 16 | x [0-9] {8} 16? $
- Whether the account is valid (starting with a letter, 5-16 bytes allowed, alphanumeric underscore allowed) :
^ [a zA - Z] [a - zA - Z0-9 _] {4, 15} $
- The password must start with a letter and contain 6 to 18 letters, digits, and underscores (_).
^ \ w [a zA - Z] {5} in 2 $
- Strong password (must contain a combination of uppercase and lowercase letters and digits, cannot use special characters, and is between 8 and 10 characters in length) :
^ (? =.*\d)(? =.*[a-z])(? =. * [a-z]). 8, 10 {} $
- Date format:
^ \ d {4} \ d {1, 2} - \ d {1, 2}
- 12 months of the year (01 ~ 09 and 1 ~ 12) :
^ (0? [1-9] [2-0]) $| 1
- 31 days of a month (01 ~ 09 and 1 ~ 31) :
^ ((0? [1-9]) | | 2 (1) ([0-9]) | | 31) $30
Input format of money:
\ 1. There are four representations of money we can accept: “10000.00” and “10000.00,” and not “points” of the “10000” and “10000” : ^ 1-9] [[0-9] * $
\ 2. This means that any one does not begin with 0, but it also means that a character “0” is not through, so we use the form below: ^ (0 | [1-9] [0-9] *) $
\3. A 0 or a number that does not start with 0. We can also allow the beginning there is a minus sign: ^ (0 | -? [1-9] [0-9] *) $
\4. This represents a 0 or a possibly negative number that does not begin with a 0. Let the user start with 0. Let’s get rid of the minus, because money can’t be negative. ^[0-9]+(.[0-9]+)? $
\ 5. Must be behind the decimal point should be at least 1 digit, so it is not through “10.”, but “10” and “10.2” is through: ^ [0-9] + (. [0-9] {2})? $
\ 6. So we must have two decimal point behind, if you think that is too harsh, it can be: ^ [0-9] + (. [0-9] {1, 2})? $
\7. This allows the user to write only one decimal digit. Below we should consider a comma in the digital, we can be like this: ^ [0-9] {1, 3} ([0-9] {3}), * (. [0-9] {1, 2})? $
8.1 to 3 digits, followed by any comma + 3 Numbers, commas become optional, rather than having to: ^ ([0-9] + | [0-9] {1, 3} ([0-9] {3}), * (. [0-9] {1, 2})? $
(Search the public account Java backend, reply “2021”, send you a Java interview questions treasure book)
Note: This is the final result, remember that + can be replaced with * if you think empty strings are acceptable (strange, why?). And finally, don’t forget to get rid of that backslash when you’re using a function, that’s where the usual mistakes are
- The XML file:
^([a-zA-Z]+-?) +[a-zA-Z0-9]+\\.[x|X][m|M][l|L]$
- Regular expressions for Chinese characters:
[\u4e00-\u9fa5]
- Double-byte characters:
[^\x00-\xff]
(Including Chinese characters, can be used to calculate the length of a string (a two-byte character length is 2, ASCII character length is 1) - Regular expressions for blank lines:
\n\s*\r
(Can be used to delete blank lines) - Regular expressions for HTML tags:
<(\S*?) [^ >] * >. *? < 1 > / \ | <. *? />
(The version circulating on the Internet is so bad that this is only partial and still does nothing for complex nested tags) - Regular expressions for leading and trailing whitespace characters:
^ | \ \ s * s * $or (^ \ s *) | (\ s * $)
A useful expression that can be used to delete whitespace at the beginning and end of a line. - Tencent QQ Id:
[1-9] [0-9] {4}
(Tencent QQ id starts from 10000) - China Postcode:
[1-9]\d{5}(? ! \d)
(6-digit postal code in China) - IP address:
\d+\.\d+\.\d+\.\d+
(Useful for extracting IP addresses) - IP address:
((? : (? :25[0-5]|2[0-4]\\d|[01]? \\d? \\d)\\.) {3} (? :25[0-5]|2[0-4]\\d|[01]? \\d? \\d))
- – v4 IP address:
\\b(? : (? : 25 [0 to 5] | 2 [0 to 4] [0-9] | [01]? [0-9] [0-9]?) \ \.) {3} (? : 25 [0 to 5] | 2 [0 to 4] [0-9] | [01]? [0-9] [0-9]?) \\b
(Useful for extracting IP addresses) - Verify IP-v6 address:
(([0-9 a - fA - F] {1, 4} {7, 7}) [0-9 a - fA - F] {1, 4} | ([0-9 a - fA - F] {1, 4} {1, 7}) : | ([0-9 a - fA - F] {1, 4} {1, 6}) : [0-9 a - fA - F] {1, 4} | ([0-9 - fA - a F] {1, 4} {1, 5}) (: [0-9 a - fA - F] {1, 4}, {1, 2} | ([0-9] a - fA - F {1, 4} {1, 4}) (: [0-9 a - fA - F] {1, 4}, {1, 3} | ([0-9 a - fA - F] {1, 4} {1, 3}) (: [0-9 - a FA - F] {1, 4} {1, 4} | ([0-9 a - fA - F] {1, 4}} {1, 2) (: [0-9 a - fA - F] {1, 4}, {1, 5} | [0-9 a - fA - F] {1, 4} : ((: [0-9 a - fA - F] {1, 4}, {1, 6}) | : ((: [0-9 - a FA - F] {1, 4} {1, 7} | :) | fe80: : [0-9 a - fA - F] {0, 4}) {0, 4} % [0-9 a zA - Z] {1} | : : (FFFF (: 0 {1, 4}) {0, 1} {0, 1} ((25) [0 to 5) | (2 [0 to 4] | 1 {0, 1} [0 9]) {0, 1} [0-9]) \ \.) {3} (25 [0 to 5) | (2 [0 to 4] | 1 {0, 1} [0-9]) {0, 1} [0-9]) | ([0-9 a - fA - F] {1, 4} {1, 4}) : ((25 [0 to 5) | (2 [0 to 4] | 1 {0, 1} [0-9]) {0, 1} [0-9]) \ \.) {3} (25 [0 to 5) | (2 | 1 [0-4] [0-9] {0, 1}) [0-9] {0, 1}))
- Subnet mask:
((? : (? :25[0-5]|2[0-4]\\d|[01]? \\d? \\d)\\.) {3} (? :25[0-5]|2[0-4]\\d|[01]? \\d? \\d))
- Calibration date:
^ (? : (? ! 0000) [0-9] {4} - (? : (? : 0 | [1-9] [0-2] 1) - (? : 0 [1-9] [0-9] | | 1 2 [0 to 8]) | (? : 0 [9] 13 - | [0-2] 1) - (? 30) : 29 | | (? : 0 [13578] 1 [02]) - 31) | | (? : [0-9] {2} (? : 0 [48] | [2468] [048] | [13579] [26]) | (? : 0 [48] | [2468] [048] | [13579] [26]) 00) - 02 - $29)
(Date verification in “YYYY-MM-DD” format, with flat leap years taken into account.) - Extract notes:
<! - (. *?) -->
- Find CSS properties:
^\\s*[a-zA-Z\\-]+\\s*[:]{1}\\s[a-zA-Z0-9\\s.#]+[;] {1}
- Extract page hyperlinks:
(<a\\s*(? ! .*\\brel=)[^>]*)(href="https? : \ \ / \ \ / ((?) ! (? : (? :www\\.) ? '.implode('|(? :www\\.) ? ', $follow_list).'))[^" rel="external nofollow" ]+)"((? ! .*\\brel=)[^>]*)(? : [^ >] *) >
- Extract web images:
\ \ < * [img] [^ \ \ \ \ >] * (SRC) * = * [\ \ "\ \ '] {0, 1} ([^ \ \ \ \ '\ \" >] *)
- Extract web page color code:
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
- File extension effect:
^([a-zA-Z]\\:|\\\\)\\\\([^\\\\]+\\\\)*[^\\/:*?"<>|]+\\.txt(l)? $
- Determine the IE version:
^.*MSIE [5-8](? : \ \. [0-9] +)? (? ! .*Trident\\/[5-9]\\.0).*$
Schedule:
PS:
- www.runoob.com/regexp/rege…
- Online regular expression tests: tool.oschina.net/regex/
If you find any error after verification, please correct it in the message area!