When you specify a subexpression with parentheses, the text that matches the subexpression (that is, what this grouping captures) can be further processed in an expression or other program.
By default, each grouping automatically has a group number, with the rule: left-to-right, with the left parenthesis of the group as the flag, the group number for the first occurrence is 1, the second is 2, and so on.
A back reference is used to repeat the search for text that precedes a grouping match.
category |
Code/Syntax |
Description |
Capture |
(exp) |
Match exp, and capture text into an automatically named group |
(? <name>exp) |
Match exp, and capture the text to a group named name, or you can write (? ') Name ' exp ') |
(?: EXP) |
Matches exp, does not capture matching text, and does not assign group numbers to this group |
0 Wide Assertion |
(? =exp) |
Match the position of the exp front |
(? <=exp) |
Match the position after exp |
(?! Exp |
Match the position followed by the exp. |
(? <!exp) |
Match a location that is not previously exp |
Comments |
(? #comment) |
This type of grouping does not have any effect on the processing of regular expressions, and is used to provide comments for people to read |
1.1 Capture
1.2 0 Wide Assertion
1.3 Notes
My opinion on regular expressions-back reference