[Turn] the most complete history of regular expression - matching English letters and numbers

In the process of doing the project, use regular expressions to match certain kinds of characters in a text, it is more commonly used as a way, the following is commonly used to make a regular match collate and analyze.

1, matching Chinese: [\ u4e00- \ u9fa5]

2, letters: [a-zA-Z]

3, numeral: [0-9]

4, matching Chinese, English letters and numbers and underscores: ^ [\ u4e00- \ u9fa5_a- zA-Z0-9] + $
simultaneously input length determination:
[\ u4e00- \ zA-u9fa5_a -Z0-9 _] {4,10}

5,
(?! _) Can not _ beginning
not end with _ (?!. *? _ $)
[A-zA-Z0-9_ \ u4e00- \ u9fa5] + at least one Chinese characters, numbers, letters, underscores
$ and end of the string place match

6, contains only characters, numbers, letters, underline, the underline position is not limited:
^ [A-zA-Z0-9_ \ u4e00- \ u9fa5] + $

. 7, string of digits, letters or underscore 26 composed
^ \ $ W +

8,2. 4 characters ~
"^ [\ u4E00- \ u9FA5] {2,4} $";

. 9, should not be longer than 7 characters, or 14 bytes (numbers, letters and underlined) regular expression
^ [\ u4e00- \ u9fa5] { 1,7} $ | ^ [\ dA-Za-z _] {1,14} $
 

10, matched double-byte characters (including characters included): [^ x00-xff]
Commentary: can be used to calculate the length of the string (a double-byte character length meter 2, ASCII characters are counted 1)

11, is a blank line to match the regular expression: ns * r
commentary: can be used to delete blank lines

12, matching HTML tags regular expression: <(S *?) [ ^>] *> * | <* />.?.?
Comment: The spread of the Internet version too bad, above this was only able to match part, for complex nested tags still powerless

13, and last blank character to match a regular expression: ^ s * | s * $
Comment: The blank character can be used to delete the beginning of the line end of the line (including spaces, tabs, page breaks, etc.), very useful expression formula

14, mice distribution Email Institute Add specular 则表 达式: ^ [a-zA-Z0-9] [\ w \ .-] * [a-zA-Z0-9] @ [a-zA-Z0-9] [\ w \ .-] * [a-zA-Z0-9] \. [a-zA-Z] [a-zA-Z \.] * [a-zA-Z] $

Commentary: When Forms authentication is very practical

15, phone number: ^ ((13 [0-9]) | (14 [0-9]) | (15 [0-9]) | (17 [0-9]) | (18 [0-9] )) \ d {8} $

16, ID: (^ \ d {15} $) | (^ \ d {17} ([0-9] | X | x) $)

17, the matching URL URL regular expression: [a-zA-z] +: // [^ s] *
Comment: The spread of the Internet version of the function is very limited, the above meet the basic needs

18, the matching account is valid (beginning with the letter, allowing 5-16 bytes to allow alphanumeric underlined): ^ [a-zA- Z] [a-zA-Z0-9 _] {4,15} $
Commentary: Form Validation when it is practical


19, domestic phone number matching: d {3} -d {8 } | d {4} -d {7}
Comment: 0511-4405222 form such as a matching or 021-87888822

20, matching Tencent QQ: [1-9] [0-9] {4,}
Comment: Tencent QQ number from 10000 start

21, matching China postal code: [1-9] d {5} (?! d)
Commentary: 6-digit ZIP code for China

22, the matching ID: d {15} | d { 18}
Commentary: China ID is 15 or 18

23, ip address matching: d + .d + .d + .d +
Commentary: ip address extraction of useful


24, matching specific numbers:
^ [1-9] * $ // d match positive integer
^ - [1-9] d * $ // matching negative integers
^ - [1-9] d * $ // match integer?
^ [1-9] d * | 0 $ // matches the non-negative integer (integer + 0) ^
- [1-9] * D | 0 $ // matching non-positive integer (negative integer + 0)
^ [1 -9] d * .d * | 0.d * [1-9] d * $ // matching positive float
^ - ([1-9] d * .d * | 0.d * [1-9] d *) $ // matching negative float
^ - ([1-9] d * .d * |? 0.d * [1-9] d * | 0 .0+ | 0) $ // match float? points
? ^ [1-9] d * .d * | 0.d * [1-9] d * | 0 .0+ | 0 $ // match non-negative floating-point numbers (positive float + 0)
^ (- ? ([1-9] d * .d * | 0.d * [1-9] d *)) | 0 .0+ | 0 $ // matching non-positive float (negative float + 0)
comments: when processing large amounts of data useful to pay attention to correcting specific application


25, a specific string matching:
^ [A-Za-Z] + $ @ matching string of 26 English letters
^ [AZ] + $ // string of 26 matches uppercase letters composed
^ [az] + $ // matching string of 26 lowercase letters consisting of
^ [a-Za-z0-9] + $ // matching string of numbers and English letters of 26
^ w + $ // matching string of digits, letters or underscore 26 composed of

26,
authentication and verification expressions when used RegularExpressionValidator validation control as follows:
only numbers: "^ [0-9] * $"
only n-bit digital input: "^ d {n} $ "
at least n-bit digital input only: "^ d {n,} $"
only input digital mn bits: "^ d {m, n } $"
can only be entered at the beginning of the zero and non-zero number: "^ (0 | [1-9] [0-9] * ) $ "
enter only have two positive real number of decimal places:" ^ [0-9] + ([0-9] {2}) $. "?
only 1-3 is input decimal digit positive real number: "(. [0-9] {1,3})? ^ [0-9] + $"
enter only nonzero positive integer:? "^ + [1 -9] [0-9] * $ "
can only enter a non-zero negative integer:" ^ - [1-9] [0-9] * $ "
only the length of the input characters 3:" {^ 3. } $ "
only by the input string 26 English letters:" ^ [a-Za- z] + $ "
only by the input string 26 English capital letters:" ^ [AZ] + $ "
only letters written by the input string 26 consisting of small: "^ [az] + $ "
only input string of numbers and English letters 26: "^ [a-Za- z0-9] + $ "
can only enter a number, string 26 consisting of letters or underscore:" ^ w $ + "
Verify User Password:" ^ [a-zA- Z] w {5,17} $ " The correct format is: beginning with the letter, the length between 6-18,
can contain characters, numbers and underscores.
Verify ^% & containing '?,; = $ "Characters such as:" [^% &', ; = $ x22?] + "
Can input Chinese characters: "^ [u4e00-u9fa5] , {0,} $"
Verify Email Address: "^ w + [-. +] W +) * @ w + ([-.] W +) * w + ([-.. ] w +) * $ "
verification InternetURL:" ^ http: // ( [w-] +) + [w-] + (/ [w-./?%&=] *) $ ".?
verify ID number (15 or 18 digits): "^ d {15} | d {} 18 $"
verification year 12 months: "^ (? 0 [1-9 ] | 1 [0-2]) $" the correct format is: "01" - "09" and "1" "12"
verify 31 days a month: "^ ((0 [1-9 ]) | ((1 | 2) [0-9])? | 30 | 31) $ "
correct format:" 01 "" 09 "and" 1 "" 31. "
Chinese characters matching the regular expression: [u4e00-u9fa5]
matching double-byte characters (including characters included): [^ x00-xff]
regular expression matching blank line: n [s |] * r
matches HTML tags regular expression:. / <(. *) > * | <(. *) /> /
matching trailing spaces regular expression: (^ s *) | ( s * $)
matches Email address regular expression: w + . ([-. +] w +) * @ w + ([-.] w +) * w + ([-.] w +) *
matches at URL regular expression: http: // ([w-] +.) + [w -] + (/ [ w- ./?%&=]*)?

Guess you like

Origin www.cnblogs.com/bluecagalli/p/11328865.html