|
Regular expressions for string manipulation, form validation, and so on, practical and efficient. But use is not always grasp that tend to check something. Now some commonly used expressions gather here to prepare for contingencies.
1. Chinese characters matching the regular expression: [\ u4e00- \ u9fa5]
2. Commentary: Match Chinese really is a headache, with this expression will be easier
3. Match double-byte characters (including Chinese characters included): [^ \ x00- \ xff]
4. Commentary: it can be used to calculate the length of the string (the length of a double-byte character count 2, ASCII character count 1)
5. Match the blank line regular expression: \ n \ s * \ r
6. Commentary: it can be used to remove blank lines
7. HTML tags matching regular expression: <(\ S *?) [^>] *> * | <* />.?.?
8. Comment: The spread of the Internet version is too bad, this is only the top part can match, for complex nested tags remain powerless
9. The first and last match whitespace regular expression: ^ \ s * | \ s * $
10. Commentary: whitespace characters delete the line end of the line can be used (including spaces, tabs, page breaks, etc.), useful expressions
11. Match Email address regular expression:. \ W + ([-. +] \ W +) * @ \ w + ([-.] \ W +) * \ \ w + ([-.] \ W +) *
12.
13. Commentary: When Forms authentication is very useful
14. URL URL matching regular expression: [a-zA-z] +: // [^ \ s] *
15. Comment: The spread of the Internet version of the very limited functionality to meet the basic needs of the above
16. Match account is valid (letter at the beginning, allow 5-16 bytes to allow alphanumeric characters and underscores): ^ [a-zA-Z] [a-zA-Z0-9 _] {4,15} $
17. Commentary: When Forms authentication is very useful
18. Match Domestic telephone number: \ d {3} - \ d {8} | \ d {4} - \ d {7}
19. Commentary: Match the form as 0511-4405222 or 021-87888822
20. Match Tencent QQ number: [1-9] [0-9] {4}
21. Commentary: Tencent QQ number 10000 from the beginning
22. Match China Postal Code: [1-9] \ d {5} (?! \ D)
23. Commentary: China 6-digit postal code
24. Match ID: \ d {15} | \ d {18}
25. Commentary: China's ID card is 15 or 18
26. Match ip address:... \ D + \ \ d + \ \ d + \ \ d +
27. Commentary: extraction of useful ip address
28. match specific figures:
29. ^ [1-9] \ d * $ // matches the positive integers
30 ^ -. [1-9] \ d * $ // matches the negative integer
31 ^ -.? [1-9] \ d * $ // matches integer
32 ^ [1-9] \ d * |. 0 $ // matches the non-negative integer (positive integer + 0)
33 ^ - [1-9] \ d * |. 0 $ // matches the non-positive integers (negative integer + 0)
. 34 ^ [1-9] \ d * \ \ d * |.. 0 \ \ d * [1-9] \ d * $ // matching positive float
. 35 ^ - (.. [1-9] \ d * \ \ d * | 0 \ \ d * [1-9] \ d *) $ // matches the negative float
.? 36 ^ - (..?. [1-9] \ d * \ \ d * | 0 \ \ d * [1-9] \ d * | 0 \ 0+ | 0) $ // match float
. 37 ^ [1-9] \ d * \ \ d * |.. 0 \ \ d * [1-9] \ d * | 0 \ 0+ |?. 0 $ // matches the non-negative floating point numbers (positive float + 0)
38 ^ (- ([1-9] \ d * \ \ d * |.. 0 \ \ d * [1-9] \ d *)) |.?. 0 \ 0+ | 0 $ // non-matching positive float (negative float + 0)
39. Commentary: When handling large amounts of data useful to pay attention to correcting specific application
40. match specific strings:
41. ^ [A-Za-z] + $ // matches a string of 26 letters of the English
42. ^ [A-Z] + $ // matches a string of 26 letters of the English capital composition
43. ^ [A-z] + $ // matches the 26 lowercase letters of the alphabet consisting of a string
44. ^ [A-Za-z0-9] + $ // matches the string of numbers and 26 letters of the English
45. ^ \ W + $ // matches a string of numbers, 26 English letters or the underscore
Commentary: some of the most basic and most commonly used expressions. |
|
|
|