| Regular metacharacters |
Meaning |
Use Cases |
| \ |
It is usually used to disable the special meaning of subsequent characters and restore the original intention. |
\ (... \), The brackets here only represent parentheses. |
| . |
Match any single character. |
A. B will match ABB, ACB, etc. |
| * |
Match a single character between 0 and N. |
A * B will match AB, AAB, aaab, etc. |
| ^ |
Match the followed regular expression at the beginning of the row. |
^ AB, which matches ABC, Abd, and so on, but does not match cab. |
| $ |
Matches the followed regular expression at the end of the row. |
AB $, will match AB, cab, etc., but does not match ABC. |
| [...] |
Square brackets match any internal characters. -Indicates the range of consecutive characters. If the ^ symbol is placed in square brackets, the first character has a reverse meaning, that is, it matches any character not in the list (square brackets. If you want] and-to indicate the original intention, You need to place them at the first character position of square brackets, such as [] AB] or [-AB]. If both characters exist at the same time, place] at the beginning and end, for example, [] AB-]. |
[A-bA-Z0-9!] All uppercase/lowercase letters, numbers, and exclamation points. [^ ABC] indicates all characters other than A, B, and C. [TT] om, which can match Tom and Tom. |
| \ {N, m \} |
An interval expression that matches the number of occurrences of a single character before it. \ {n \} indicates n times of repetition; \ {n, \} indicates at least N times of repetition; \ {n, m \} indicates repeated n to m times. |
AB \ {2 \} indicates abb; AB \ {2, \} indicates ABB and abbb. AB \ {2, 4 \} indicates ABB, abbb, and abbbb. |
| \(...\) |
The mode between parentheses is stored in a special "reserved space ". A maximum of nine independent sub-modes can be stored in a single mode. Text that matches the sub-mode can be reused in the same mode through escape sequence \ 1 to \ 9. |
\ (AB \). * \ 1 indicates that the AB combination appears twice, and there can be any number of characters between the two, such as abcdab and Abab. |
| {N, m} (ERE) |
The function is equivalent to the above \ {n, m \}, but the \ escape character is no longer written. |
AB + matches AB and abbb, but does not match. |
| + (ERE) |
Compared with the asterisk, + matches 1-N instances of the regular expression. |
|
| ? (ERE) |
Match the First Regular Expression with 0 or 1. |
AB? Only a or AB is matched. |
| | (ERE) |
Match with | the regular expression before and after the symbol. |
(AB | cd) matches AB or CD. |
| [: Alpha:] |
Match letter characters. |
[[: Alpha:]!] AB $ matches cab, dab, and! AB. |
| [: Alnum:] |
Matches letters and numbers. |
[[: Alnum:] AB $ matches 1AB and AAB. |
| [: Blank:] |
Matches spaces and tab characters. |
[[: Alnum:] AB $ matches 1AB and AAB. |
| [: Cntrl:] |
Match control characters. |
|
| [: Digit:] |
Match numeric characters. |
|
| [: Graph:] |
Matches non-space characters. |
|
| [: Lower:] |
Match lowercase letters. |
|
| [: Upper:] |
Match uppercase letters. |
|
| [: Punct:] |
Match punctuation characters. |
|
| [: Space:] |
Matches whitespace characters. |
|
| [: Xdigit:] |
Match the hexadecimal number. |
|
| \ W |
Match any character consisting of letters and numbers, equivalent to [[: alnum:] _] |
|
| \ W |
Match any character consisting of non-letters and numbers, equivalent to [^ [: alnum:] _] |
|
| \ <\> |
Match the start and end of a word. |
\ <Read matches README, me \> matches readme. |