分组构造(Grouping constructs)

优质
小牛编辑
127浏览
2023-12-01

分组构造描述正则表达式的子表达式并捕获输入字符串的子字符串。 下表列出了分组结构 -

分组构造描述图案火柴
( subexpression )捕获匹配的子表达式并为其指定从零开始的序数。(\w)\1"ee" in "deep"
(?< name >subexpression)将匹配的子表达式捕获到命名组中。(?\w)\ k"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”,“A12XL”,“A12xl A12XL a12xl”
(?= subexpression)Zero-width positive lookahead assertion.\w+(?=\.)“是”,“跑”,“出”,“他是。狗跑了。太阳出来了。”
(?! subexpression)Zero-width negative lookahead assertion.\b(?!un)\w+\b“确定”,“使用”在“不确定确定统一使用”
(?< =subexpression)Zero-width positive lookbehind assertion.(?<= 19)\ d {2}\b“1851 1999 1950 1905 2003”中的“99”,“50”,“05”
(?< ! subexpression)Zero-width negative lookbehind assertion.(?“1851 1999 1950 1905 2003”中的“51”,“03”
(?> subexpression)Nonbacktracking (or "greedy") subexpression.[13579](?>A+B+)“1ABB 3ABBC 5AB 5AC”中的“1ABB”,“3ABB”和“5AB”