Locator characters |
|
|
\b |
Match the beginning or end of a word |
|
\b |
Match a position that is not the beginning or end of a word |
|
^ |
Match the start of a string |
|
$ |
Match the end of a string |
|
Content Matching |
|
|
\w |
Match letters or numbers or underscores or kanji |
|
\w |
Matches characters that are not letters or numbers or underscores or kanji |
|
\d |
Match numbers |
|
\d |
Match non-numeric |
|
\s |
Match any of the whitespace characters |
|
\s |
Match any non-whitespace character |
|
. |
Match any character other than line break |
|
\f |
Match a page break |
|
\ n |
Match a line break |
|
\ r |
Match a carriage return character |
|
\ t |
Match a tab |
|
\v |
Match a vertical tab |
|
Quantity Matching |
|
|
* |
Repeat 0 or more times |
|
? |
Repeat 0 or one time |
|
+ |
Repeat one or more times |
|
N |
Repeat n times |
|
{N,} |
Repeat n times, or more |
|
{N,m} |
Repeat N to M times |
|
Selectable Options Match |
|
|
[ABC] |
Match any one of the characters in [] |
|
[0-9a-z] |
Match any one of the characters in 0-9 or A-Z |
|
[^0-9] |
Match any one character beyond 0-9 |
|
Branch conditions |
|
|
| |
Branching conditions (or logic) |
When using branching conditions, be aware of the order of each condition. logically more rigorous match expressions should be placed in front . When matched, each condition will be tested from left to right, and if a branch is satisfied, it will not be able to control the other conditions . |
Group |
|
|
() |
You can use parentheses to specify sub-expressions (grouping) |
For sub-expressions it is possible to set the number of loops uniformly |
Backward reference |
|
|
(exp) |
Match exp, and capture text into an automatically named group |
Citation: \index Index is the group number assigned from left to right |
(? <name>exp) |
Match exp, and capture the text to a group named name, or you can write (? ') Name ' exp ') |
\k<nmae> |
(?: EXP) |
Matches exp, does not capture matching text, and does not assign group numbers to this group |
|
0 Wide Assertion |
|
|
(? =exp) |
Matches the position of the exp front [describes the relationship between exp and the previous section] |
For example: \b\w+ (? =ing\b) finds the location where the ing\b matches, and then ing\b to the end to determine the content of the \b\w+ match |
(? <=exp) |
Match the position after exp [describe the relationship between Exp and the back part] |
For example: (? <=\bre) \w+\b first find the location of the \bre match, and then \bre to the beginning to determine the content of the \w+\b match |
Negative 0 Wide Assertion |
|
|
(?! Exp |
The match is followed by a position that is not exp [describes the relationship between exp and the previous section] |
For example: \d{3} (?! \d) First find the string that matches the \d{3}, and then determine that the content behind it does not match \d |
(? <!exp) |
Match the position of the previous not exp [describe the relationship between Exp and the back part] |
For example: (? <![ A-z]) \d{7} First find the string that matches the \d{7} and then determine that the previous content does not match [a-z] |
Comments |
|
|
(? #注释文本) |
The content inside the parentheses is a comment |
|
#注释文本 |
The current line, #之后的内容全部为注释 |
|
Greed and laziness |
|
|
Greedy match: When a regular expression contains a qualifier that can accept duplicates, the usual behavior is to match as many characters as possible (in the premise that the entire expression can be matched). |
Lazy match: Just match as few characters as possible. Just add a question mark to the back, and you can convert it. |
|
Match priority: The regular expression has another rule that has a higher priority than the lazy/greedy rule: the first match has the highest priority |
*? |
Repeat any number of times, but repeat as little as possible |
|
+ |
Repeat 1 or more times, but repeat as little as possible |
|
?? |
Repeat 0 or 1 times, but repeat as little as possible |
|
{n,m}? |
Repeat N to M times, but repeat as little as possible |
|
{N,}? |
Repeat more than n times, but repeat as little as possible |
|
Processing options (. NET support) |
|
|
IgnoreCase (ignoring case) |
Match is not case-sensitive. |
|
Multiline (multi-line mode) |
Change the meaning of ^ and $ so that they match at the beginning and end of each line, and not just at the beginning and ending of the entire string. (In this mode, the exact meaning of $ is: match the position before \ n and the position before the end of the string.) |
|
Singleline (single-line mode) |
Change the meaning of the. To make it match every character (including newline characters \ n). |
|
Ignorepatternwhitespace (Ignore whitespace) |
Ignores non-escaped whitespace in an expression and enables comments marked by #. |
|
Explicitcapture (Explicit capture) |
Only groups that have been explicitly named are captured. |
|
such as: regex regex = new Regex (@ "\ba\w{6}\b", regexoptions.ignorecase); |
|
Note: Multi-line mode and single-line mode can be enabled at the same time, there is no relationship between the two options, except that their names are more similar. |
|
|