C# - 交替结构正则表达式

交替结构修改正则表达式以启用"或/非"匹配。下表列出了交替结构 -

交替结构 描述 模式 匹配
| 匹配由竖线 (|) 字符分隔的任意一个元素。 th(e|is|at) "the", "this" in "this is the day. "
(?( expression )yes | no ) 如果表达式匹配,则匹配 yes;否则,匹配可选的 no 部分。表达式被解释为零宽度断言。 (?(A)A\d{2}\b|\b\d{3}\b) "A10 C103 910" 中的"A10", "910"
(?( name )yes | no ) 如果指定的捕获名称匹配,则匹配 yes;否则,匹配可选的 no (?< quoted>")?(?(quoted).+!"|\S+\s) Dogs.jpg, "Yiska playing.jpg" 在 "Dogs.jpg "Yiska playing.jpg"" 中

csharp_regular_expressions.html