VB.Net 正则表达式 - 分组结构
分组结构描述正则表达式的子表达式并捕获输入字符串的子字符串。 下表列出了分组结构 −
分组结构 | 描述 | 模式 | 匹配 |
---|---|---|---|
( subexpression ) | 捕获匹配的子表达式并为其分配一个从零开始的序数。 | (\w)\1 | "ee" in "deep" |
(?< name >subexpression) | 将匹配的子表达式捕获到命名组中。 | (?< double>\w)\k< double> | "ee" in "deep" |
(?< name1 -name2 >subexpression) | 定义一个平衡组定义。 | (((?'Open'\()[^\(\)]*)+((?'Close-Open'\))[^\(\)]*)+)*(?(Open)(?!))$ | "((1-3)*(3-1))" in "3+2^((1-3)*(3-1))" |
(?: subexpression) | 定义非捕获组。 | Write(?:Line)? | "WriteLine" in "Console.WriteLine()" |
(?imnsx-imnsx:subexpression) | 应用或禁用subexpression(子表达式)内的指定选项。 | A\d{2}(?i:\w+)\b | "A12xl", "A12XL" in "A12xl A12XL a12xl" |
(?= subexpression) | 零宽度正向先行断言。 | \w+(?=\.) | "is", "ran", and "out" in "He is. The dog ran. The sun is out." |
(?! subexpression) | 零宽度负先行断言。 | \b(?!un)\w+\b | "sure", "used" in "unsure sure unity used" |
(?< =subexpression) | 零宽度正向后断言。 | (?< =19)\d{2}\b | "51", "03" in "1851 1999 1950 1905 2003" |
(?< ! subexpression) | 零宽度负回顾断言。 | (?< !19)\d{2}\b | "ends", "ender" in "end sends endure lender" |
(?> subexpression) | 非回溯(和"贪婪")子表达式。 | [13579](?>A+B+) | "1ABB", "3ABB", and "5AB" in "1ABB 3ABBC 5AB 5AC" |
❮ vb.net_regular_expressions.html