^: (Read: hat) match the beginning of a row. For example, the regular expression "^ regex" can match the start of the string "regex I will use", but cannot match "I will use regex ".
$: Similar to ^. It matches the end.
| Representation or z | food indicates z or food is not zood or food
[] Match any character in brackets
. (Point) matches any single character except n.
*: A qualifier that matches up to 0 subexpressions before it. It has nothing to do with the wildcard.
+: A qualifier, similar to *, but must appear once.
? : Similar to *, but the value is 0 or 1.
{}: The limit symbol, indicating the number of times that must be filled in brackets before the character. For example, [0-9] {6} indicates that any number in 0-9 must appear 6 times.
{,}: For example, [0-9] {6,} indicates that at least 6 occurrences are displayed, and the maximum number of occurrences is unlimited. [0-9] {6, 10} indicates at least 6 times, up to 10 times.
D: represents a number, equivalent to [0-9] \ d & rarr; d
D: indicates a non-number, which is equivalent to [^ 0-9].
S: blank characters such as line breaks and Tab tabs (space, carriage return, and Tab)
S: non-blank characters (a0% $ @@)
W: matches letters, numbers, underscores, or Chinese characters. It can be a word character, except % &#@! $ And other characters. [A-zA-Z0-9 _ Chinese characters]
W: Not w, equivalent to [^ w] %
Qualifier
A qualifier provides a simple method to specify the number of times a specific character or character set can appear repeatedly in the mode. There are three non-explicit delimiters:
*, The description "appears 0 or multiple times ".
+, The description "appears one or more times ".
?, The description "appears 0 or 1 time ".
The qualifier always references the pattern before the qualifier (left), usually a single character, unless you create a pattern group using parentheses. Below are some examples of the pattern and matched input.
Mode
Input (matching)
Fo *
Foo, foe, food, fooot, "forget it", funny, puffy
Fo +
Foo, foe, food, foot, "forget it"
Fo?
Foo, foe, food, foot, "forget it", funny, puffy
The following describes some common
Matching domestic phone number: d {3}-d {8} | d {4}-d {7} remarks: matching format: 0511-4405222 or 021-87888822
Match Tencent QQ number: [1-9] [0-9] {4,} remarks: Tencent QQ number starts from 10000
Match China Zip code: [1-9] d {5 }(?! D) Commentary: China post code is a six-digit number.
ID card matching: d {15} | d {18} remarks: Chinese ID cards are 15 or 18 characters
Matching IP address: d +. d + remarks: useful when IP addresses are extracted
Match a certain range: @ "<table> [sS] +? </Table>"
Matched connection address: </? (A | A) (. *?> |>)
Match a specific number:
^ [1-9] d * $ // match a positive integer
^-[1-9] d * $ // match a negative integer
^ -? [1-9] d * $ // match the integer
^ [1-9] d * | 0 $ // match a non-negative integer (positive integer + 0)
^-[1-9] d * | 0 $ // match a non-positive integer (negative integer + 0)
^ [1-9] d *. d * | 0. d * [1-9] d * $ // match the positive floating point number
^-([1-9] d *. d * | 0. d * [1-9] d *) $ // match the negative floating point number
^ -? ([1-9] d *. d * | 0. d * [1-9] d * | 0 ?. 0 + | 0) $ // Match floating point number
^ [1-9] d *. d * | 0. d * [1-9] d * | 0 ?. 0 + | 0 $ // Match non-negative floating point number (positive floating point number + 0)
^ (-([1-9] d *. d * | 0. d * [1-9] d *) | 0 ?. 0 + | 0 $ // Match non-positive floating-point number (negative floating-point number + 0) comments: useful when processing a large amount of data, pay attention to correction when using
Match a specific string:
^ [A-Za-z] + $ // match A string consisting of 26 English letters
^ [A-Z] + $ // match a string consisting of 26 uppercase letters
^ [A-z] + $ // match a string consisting of 26 lowercase letters
^ [A-Za-z0-9] + $ // match a string consisting of digits and 26 letters
^ W + $ // match a string consisting of digits, 26 English letters, or underscores
Mode
Description
^ D {5} $
Five numeric numbers, such as the US postal code.
^ (D {5}) | (d {5}-d {4} $
5 numeric or 5 Numeric-dashes-4 numeric. Match the United States postal code in 5-digit format, or the United States postal code in 5-digit + 4-digit format.
^ (D {5} (-d {4 })? $
Same as the previous one, but more effective. Use? The four digits in the mode can be used as the optional part, instead of comparing two different modes (in another way ).
^ [+-]? D + (. d + )? $
Matches any real number with an optional symbol.
^ [+-]? D *.? D * $
It is the same as the previous one, but it also matches an empty string.
^ (20 | 21 | 22 | 23 | [01] d) [0-5] d $
Matches the time value in the 24-hour format.
/*.**/
Matching C-style comments /*...*/
1. verify the username and password: ("^ [a-zA-Z] w {5, 15} $") correct format: "[A-Z] [a-z] _ [0-9]", and the first word must be 6 ~ 16 bits;
2. Verify the phone number :( "^ (d {3.4}-) d {} $") in the correct format: xxx/xxxx-xxxxxxx/xxxxxxxx;
3. Verify the ID card number (15 or 18 digits): ("^ d {15} | d {18} $ ");
4. verify Email Address: ("^ w + ([-+.] w +) * @ w + ([-.] w + )*. w + ([-.] w +) * $ ");
5. You can only enter a string consisting of a number and 26 English letters :( "^ [A-Za-z0-9] + $ ");
6. Integer or decimal point: ^ [0-9] +. {} [0-9] {} $
7. Only numbers can be entered: "^ [0-9] * $ ".
8. Only n digits can be entered: "^ d {n} $ ".
9. You can only enter at least n digits: "^ d {n,} $ ".
10. Only m ~ can be input ~ N-digit :. "^ D {m, n} $"
11. Only numbers starting with zero and non-zero can be entered: "^ (0 | [1-9] [0-9] *) $ ".
12. Only positive numbers with two decimal places can be entered: "^ [0-9] + (. [0-9] {2 })? $ ".
13. Only 1 ~ Positive number of three decimal places: "^ [0-9] + (. [0-9] {1, 3 })? $ ".
14. Only non-zero positive integers can be entered: "^ +? [1-9] [0-9] * $ ".
15. Only a non-zero negative integer can be entered: "^-[1-9] [] 0-9" * $.
16. Only three characters can be entered: "^. {3} $ ".
17. You can only enter A string consisting of 26 English letters: "^ [A-Za-z] + $ ".
18. Only a string consisting of 26 uppercase letters can be entered: "^ [A-Z] + $ ".
19. You can only enter a string consisting of 26 lower-case English letters: "^ [a-z] + $ ".
20. Verify whether ^ % & ',; =? $ "And other characters:" [^ % & ',; =? $ X22] + ".
21. Only Chinese characters can be entered: "^ [u4e00-u9fa5] {0,} $"
22. Verify URL: "^ http: // ([w-] +.) + [w-] + (/[w -./? % & =] *)? $ ".
23. Verify 12 months of the year: "^ (0? [1-9] | 1 [0-2]) $ "the correct format is:" 01 "~ "09" and "1 "~ "12 ".
24. 31 days of verification for a month: "^ (0? [1-9]) | (1 | 2) [0-9]) | 30 | 31) $ "the correct format is;" 01 "~ "09" and "1 "~ "31 ".
In conclusion, php jsp java moderate regular expressions in asp.net are of the same significance, and their rules are similar, regular expressions are a very troublesome task. Many programmers only have the most basic skills. I think everyone just needs to use the above.