Common regular expression formula summary

First, the check digit of expression

  1. Digital: ^ [0-9] * $

  1. The number n of bits: ^ d {n} $

  1. At least an n-bit number: ^ d {n,} $

  1. Mn-bit numbers: ^ d {m, n} $

  1. Digital zero and non-zero at the beginning: ^ (0 | [1-9] [0-9] *) $

  1. Beginning with zero up to two decimal places: (. [0-9] {1,2})? ^ ([1-9] [0-9] *) $ +

  1. 1-2 decimal number with a positive or negative:? ^ (-) d + (. D {1,2}) $

  1. Positive, negative, and decimals:?? ^ (- | +) d + (. D +) $

  1. Two positive real number of decimal places: (. [0-9] {2})? ^ [0-9] + $

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

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

  1. Negative integer zero: ^ - [1-9] [] 0-9 "or * ^ $ - [1-9] * $ D

  1. Non-negative integers: ^ d + $ or ^ [1-9] d * | 0 $

  1. Non-positive integer: ^ - [1-9] d * | 0 $ or ^ ((- d +) | (0 +)) $

  1. ? Non-negative floating-point numbers: ^ d + (. D +) $ or ^ [1-9] d * .d * | 0.d * [1-9] d * | 0 .0+ | 0 $?

  1. Non-positive float: (.?.? (- d + (d +)) | (0 + (0 +))) ^ $ or ^ (- ([1-9] d * .d * | 0.d * [ 1-9] d *)) | 0 .0+ |? 0 $

  1. 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] *)) $

  1. Negative 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] *))) $

  1. Float: ^ (- d +?) $ Or ^ - ([1-9] d * .d * | 0.d * [1-9] d * | 0 .0+ | 0 (d +.)??? ) $

Second, check character expression

  1. Characters: ^ [a - 龥] {0,} $

  1. Alphanumeric: ^ [A-Za-z0-9] + $ or ^ [A-Za-z0-9] {4,40} $

  1. All characters in length is 3-20: {^} $ 3,20.

  1. A string consisting of letters 26: ^ [A-Za-z] + $

  1. String 26 from the English capital letters: ^ [AZ] + $

  1. String consists of 26 lowercase English letters: ^ [az] + $

  1. String of digits and letters of the English 26: ^ [A-Za-z0-9] + $

  1. String of digits, letters or underscore 26 consisting of: ^ w + $ or ^ w {3,20} $

  1. Chinese, English, numbers underlined comprising: ^ [a - 龥 A-Za-z0-9 _] + $

  1. Chinese, English, numbers, symbols such as but not underlined: ^ [a - 龥 A-Za-z0-9] + $ ^ or [a - 龥 A-Za-z0-9] {2,20} $

  1. - disable input characters comprising: [~ ^ "] +

Third, the special needs of expression

  1. Email地址:^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$

  1. 域名: [a-zA-Z0-9] [- a-zA-Z0-9] {0,62} (/. [A-zA-Z0-9] [- a-zA-Z0-9] {0 , 62}) + /.

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

  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} $

  1. Domestic telephone number (0511-4405222,021-87888822): d {3} -d {8} | d {4} -d {7}

  1. Phone number regular expression (support phone number, area code 3-4, 7-8 live numbers 1-4 digit extension number): ((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})) $)

  1. ID number (15, 18 digits), the last digit is a check digit, or may be a digital character X: (^ d {15} $) | (^ d {18} $) | (^ d {17 } (d | X | x) $)

  1. Account is valid (beginning with the letter, allowing 5-16 bytes to allow alphanumeric underlined): ^ [a-zA-Z] [a-zA-Z0-9 _] {4,15} $

  1. Password (start with a letter, a length between 6 and 18, can contain letters, numbers and underscores): ^ [a-zA-Z] w {5,17} $

  1. Strong passwords (which 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]) [a-zA-Z0-9] {8,10} $

  1. 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) (= * [(= * [az]?.)?. AZ]). {8,10} $

  1. Date format: ^ d {4} -d {1,2} -d {1,2}

  1. A year of 12 months (01 ~ 09 and 1 ~ 12): ^ (0 [1-9] | 1 [0-2]?) $

  1. Month of 31 days (01 ~ 09 and 1 ~ 31): ^ ((0 [1-9]) | ((1 | 2) [0-9]) | 30 | 31?) $

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

  1. Chinese characters in regular expressions: [a - 龥]

  1. Blank line regular expression: s * (can be used to delete blank lines)

  1. HTML markup regular expression: <(S *?) [^>] *> * | <* /> (Inclusive blank character regular expression:.?.? ^ S * | s * $ or (^ s * ) | (s * $) (it can be used to remove white space character of the line end of the line (including spaces, tabs, page breaks, etc.), very useful expression)

  1. Tencent QQ: [1-9] [0-9] {4,} (Tencent QQ number 10000 from the start)

  1. China Postal Code: [1-9] d {5} (?! d) (6-digit ZIP code for China)

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

No micro-channel public attention and headlines today, excellent article continued update. . . . .

 

 

Guess you like

Origin blog.csdn.net/wufaliang003/article/details/92943092