Csharp-alternation-constructs
提供:Dev Guides
C#-交替は正規表現を構築します
代替コンストラクトは、正規表現を変更して、いずれかまたは両方の一致を有効にします。 次の表は、代替構成を示しています-
Alternation construct | Description | Pattern | Matches |
---|---|---|---|
* | * | Matches any one element separated by the vertical bar ( | ) character. |
th(e | is | at) | "the", "this" in "this is the day. " |
*(?( expression )yes | no )* | Matches yes if expression matches; otherwise, matches the optional no part. Expression is interpreted as a zero-width assertion. | (?(A)A\d{2}\b |
\b\d{3}\b) | "A10", "910" in "A10 C103 910" | *(?( name )yes | no )* |
Matches yes if the named capture name has a match; otherwise, matches the optional no. | (?< quoted>")?(?(quoted).+?" | \S+\s) | Dogs.jpg, "Yiska playing.jpg" in "Dogs.jpg "Yiska playing.jpg"" |