Regular expressions are used to match strings.
I. Matching mode text:
The regular expression's matching mode text usually includes the following content:
Metacharacters: special characters;
| Metacharacters |
Description |
| . |
Match any character except linefeed |
| \ W |
Match letters, numbers; C # also supports Chinese characters; equivalent to [a-zA-Z0-9] |
| \ W |
In contrast to the above, matching non-digit letters; equivalent to [^ a-zA-Z0-9] |
| \ S |
Match blank characters |
| \ S |
On the contrary, non-blank characters are matched. |
| \ D |
Matching number |
| \ D |
In contrast, match non-Numbers |
| \ B |
Match the start or end of a wordLocation |
| \ B |
In contrast to the above, matching non-word start or endLocation |
| ^ |
Start position of matching string |
| $ |
End position of matching string |
Indicates the number of repetitions:
| Category |
Description |
| ? |
Indicates that the left part is repeated 0 times or 1 time. |
| * |
Indicates that the left part is repeated 0 times or multiple times. |
| + |
Indicates that the left part is repeated once or multiple times. |
| {Min, max} |
Indicates that the left part is repeated for min to Max times. |
| {Min ,} |
Indicates that the left part is repeated for at least min. |
| {Num} |
Indicates that the part on the left is repeated for num times. |
Indicates the group:
| Category |
Syntax |
Description |
| Capture |
(ABC) |
Match ABC and capture the text to the automatically named group. Or, it indicates the pattern text applicable to repeated times, |
| (? <Name> ABC) |
Match exp and capture the text to the group named name. You can also write (? 'Name' exp) |
| (? : ABC) |
Match exp, no group number is assigned to the group, and no matching text is captured. However, group 0 is not affected. |
| |
|
|
| Assertions |
(? = ABC) |
Match ABC, But ABC is not matched. That is, ABC must be followed by the text, but ABC is not obtained for group 0. |
| (? <ABC) |
If ABC is matched but ABC is not matched, the text must be preceded by ABC, but the group 0 does not get ABC. |
| (?! ABC) |
If the text to be matched is not followed by ABC, But ABC is not matched, group 0 does not get ABC. |
| (? <! ABC) |
If the text is not ABC before the match, but ABC is not matched, the ABC is not obtained for group 0. |
| |
|
|
| Note |
(? # Comment) |
Note |
| |
|
|
Others:
| Category |
Description |
| [ABC] |
Match any one of the ABC characters in the brackets (one character must be matched) |
| [^ ABC] |
Match a character other than the characters in parentheses (one character must be matched) |
| | |
Expression or; match | the previous mode or the subsequent mode |
| \ Char |
Match special characters, such as \ * match *;\? Matching? |
| |
|
| \ Num |
Reverse reference |
Indicates the text captured by the num capturing parentheses (the bracket count is calculated based on the order in which left parentheses appear. Note that nested parentheses are used)
|
Regular Expressions-Basic Knowledge