C# - 分組結構



分組結構描述正則表示式的子表示式並捕獲輸入字串的子字串。下表列出了分組結構:

分組結構 描述 模式 匹配
( 子表示式 ) 捕獲匹配的子表示式併為其分配一個基於零的序數。 (\w)\1 "deep"中的"ee"
(?< name >子表示式) 將匹配的子表示式捕獲到命名組中。 (?< double>\w)\k< double> "deep"中的"ee"
(?< name1 -name2 >子表示式) 定義平衡組定義。 (((?'Open'\()[^\(\)]*)+((?'Close-Open'\))[^\(\)]*)+)*(?(Open)(?!))$ "3+2^((1-3)*(3-1))"中的"((1-3)*(3-1))"
(?: 子表示式) 定義非捕獲組。 Write(?:Line)? "Console.WriteLine()"中的"WriteLine"
(?imnsx-imnsx:子表示式) 子表示式內應用或停用指定的選項。 A\d{2}(?i:\w+)\b "A12xl", "A12XL" in "A12xl A12XL a12xl"
(?= 子表示式) 零寬正向斷言。 \w+(?=\.) "He is. The dog ran. The sun is out."中的"is", "ran"和"out"
(?! 子表示式) 零寬負向斷言。 \b(?!un)\w+\b "unsure sure unity used"中的"sure", "used"
(?< =子表示式) 零寬正向後顧斷言。 (?< =19)\d{2}\b "1851 1999 1950 1905 2003"中的"99", "50", "05"
(?< ! 子表示式) 零寬負向後顧斷言。 (?< !19)\d{2}\b "1851 1999 1950 1905 2003"中的"51", "03"
(?> 子表示式) 非回溯(或“貪婪”)子表示式。 [13579](?>A+B+) "1ABB 3ABBC 5AB 5AC"中的"1ABB", "3ABB"和"5AB"
csharp_regular_expressions.htm
廣告
© . All rights reserved.