Regular Expression Mind mapping, no longer difficult to understand
01
A mind Map
02
Guide Map Content Analysis
Tools
Regexbuddy
Grammatical structure
Character
[ab5@]
Match "A" or "B" or "5" or "@"
[^ABC]
Matches any character except A, B, c
[F-k]
Match the characters between "F" and "K"
[^a-f0-3]
Matches any character except "a"-"F", "0"-"3"
\d
Any number, 0~9
\w
Any letter, number, Chinese character, or underscore, a~z, A~z, 0~9, _, and any of the Chinese characters
\s
Any whitespace character, including spaces, tabs, newline characters
.
The decimal point can match any one character, except for line breaks (if you want to match all characters, including "\ n", generally [\s\s])
Ordinary characters: Letters, numbers, Chinese characters, underscores, matching one character
Simple escape characters: \ n (newline), \ t (tab), \ \ (\ itself), and \^ ... (\^ and other symbols with special effects are escaped if they are to match their own words)
Standard Character Set
Note Case-sensitive, uppercase is the opposite meaning, matching the opposite is mismatched
Custom Character Set Collection
[] square brackets match, can match any one of the characters in square brackets, ^ represents the inverse
Quantifier (quantifier)
Modifies the previous expression, and if you want to decorate more than one expression, wrap the expression with ().
Greedy mode (default)
Match the longest string that matches
Non-greedy mode (added after quantifier) Example: {m,n}? )
Match the shortest string that matches
N
Expression Repeats n times
{M,n}
Expression repeats at least m times and repeats up to n times
{m,}
Expression repeats at least M-times
。
Match expression 0 or 1 times, equivalent to {0,1}
+
Expression appears at least once, equivalent to {1,}
*
expression does not appear or occurs any time, equivalent to {0,}
Character bounds
0 Width: Matches a location that is not a character but a position that conforms to a certain condition
^
Match where the string starts
$
Match where the string ends
\b
Matches the bounds of a word, the characters before the current position and the characters that follow are not all \w
Pre-search (0 wide assertion, surround look)
0 Width: Matches a location that is not a character but a position that conforms to a certain condition
(? =exp)
The assertion itself appears after the position can match the expression exp
(?! Exp
The assertion itself appears behind a position that cannot match an expression exp
(? <=exp)
The assertion itself appears before the position can match an expression exp
(? <!exp)
The assertion itself appears in front of the position cannot match the expression exp
Matching mode
How text is handled
Each line is a string
In multiline mode, if you need to match only the starting and ending positions of strings, you can use \a and \z
The entire text is treated as a string with only one end at the beginning
Make the decimal point "." You can match any character that contains a newline character (\ n)
Ignore case when matching
The default is case-sensitive
IGNORECASE Ignoring case mode
Singleline Single-line mode
MULTILINE Multi-line mode
Selectors and groupings
Branching structure, capturing combined non-capturing groups
(1), the expression in parentheses can be modified as a whole when the number of matches is modified.
(2), when the matching results are taken, the expression in parentheses matches the content can be obtained separately
(3), each pair of parentheses is assigned a number, and the capture using () is automatically numbered from 1, based on the order of the opening brackets. Capturing the first capture numbered zero is the text of the entire regular expression pattern match
Reverse reference: You can reference a grouped captured string by using a reverse reference.
| Branching structure
The "or" relationship between the left and right expressions,
() Capture Group
(?: expression) non-capturing group
in some expressions, you have to use (), but you do not need to save () the content of a neutron expression match, you can use a non-capturing group to counteract () the side effects.