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



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

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

© . All rights reserved.