You can specify the matching characters in []. For example, "a [nbc] c" can match "anc", "abc", and "acc "; but it cannot match "ancc". a to z can be written as [a-z], 0 to 9 can be written as [0-9]
1. "." is a wildcard that represents any character. For example, "a. c" can match "anc", "abc", and "acc ";
2. "[]", you can specify the matching characters in [], for example: "a [nbc] c" can match "anc", "abc", and "acc", but it cannot match "ancc". a to z can be written as [a-z], 0 to 9 can be written as [0-9];
3. quantity limit symbol, indicating the number of matching times (or length:
Including: "*" -- 0 or multiple times
"+" -- Once or multiple times
"?" -- 0 or 1 time
"{N}" -- match n times, n is an integer
"{N, m}" -- number of times a number is matched from n to m; n and m are integers;
"{N ,}" -- match any number of times between n and infinity;
"{, M}" -- match any number of times between 0 and m;
They are placed behind the matching format:
For example:
Phone number: 0755-12345678,075512345678 (assume the first 3 or 4 digits, the last 7 or 8 digits, and the minus sign in the middle is optional)
All are compliant, so you can use the following format to match: [0-9] {3, 4 }\-? [0-9] {7,8 };
Note: "\" is an escape character, because "-" represents a range in a regular expression, for example, [0-9],
Therefore, the escape character "\" is required for conversion;
4. "^" indicates no, indicating the symbols that do not match, for example: [^ z] [a-z] + can match all strings except those starting with "z" (length greater than 2, because "+" indicates the number of times greater than or equal to 1, lowercase English characters from the second digit );
If ^ is placed outside [], it indicates a string starting with []; ^ [az] [a-z] + indicates an English string starting with a or z with a length greater than or equal to 2;
5. "|" or operator. For example, a [n | bc | cb] c can match "abcc", "anc", and "acbc ";
6. "$" ends with the character above it. For example, AB + $ can be matched by "abb" and "AB;
7. Some Simple Representation Methods:
\ D represents [0-9]; \ D represents [^ 0-9]; \ w represents [A-Z0-9]; \ W represents [^ A-Z0-9]; \ s indicates [\ t \ n \ r \ f], that is, the space characters include tab, space, and so on; \ S indicates [^ \ t \ n \ r \ f], it is a non-space character;
8. Common matching:
Match Chinese characters: "[\ u4e00-\ u9fa5]";
Match double-byte characters (including Chinese characters): "[^ \ x00-\ xff]";
Match the regular expression of the blank line: \ n [\ s |] * \ r ";
Match the regular expression marked in HTML: "/<(. *)>. * <\/\ 1> | <(. *) \/> /";
Regular Expression matching the first and last spaces: "(^ \ s *) | (\ s * $ )";
Match a non-negative integer (positive integer + 0): "^ \ d + $ ";
Match a positive integer: "^ [0-9] * [1-9] [0-9] * $ ";
Match a non-positive integer (negative integer + 0): "^ (-\ d +) | (0 +) $ ";
Match a negative integer: "^-[0-9] * [1-9] [0-9] * $ ";
Matched INTEGER: "^ -? \ D + $ ";
Match non-negative floating point number (Positive floating point number + 0): "^ \ d + (\. \ d + )? $"
Match Positive floating point number: "^ ([0-9] + \. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ ";
^ (-\ D + (\. \ d + )?) | (0 + (\. 0 + )?)) $ // Match a non-Positive floating point number (negative floating point number + 0)
^ (-([0-9] + \. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ // matches a negative floating point number.
Match floating point: "^ (-? \ D +) (\. \ d + )? $ ";
Match a string consisting of digits, 26 English letters, or underscores: "^ \ w + $ ";
Matching email address: "^ [\ w-] + (\. [\ w-] +) * @ [\ w-] + (\. [\ w-] +) + $ ";
Match url: "^ [a-zA-z] +: // match (\ w + (-\ w + )*)(\. (\ w + (-\ w + )*))*(\? \ S *)? $"