Common grouping Syntax
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 |
Extract Payaccno in the middle of the account string input = @ " <payaccno>6227000000000000001</payaccno> <payaccname > Zhang San </payaccname> <payaccno>6227000000000000002</payaccno> <payaccname> John Doe </payaccname> "; Regex reg = new Regex (@ "(?<=<payaccno>) (\d+) (?=</payaccno>) +"), var matches = Reg. Matches (input); string result = ""; foreach (var m in Matches) { result + = m + ",";} result = result. TrimEnd (', ');//Result: 6227007201840000001,6227007201840000002
C # Regular Extraction Small example