交替构造修改正则表达式以启用/或匹配。下表列出了交替结构:
|
- 匹配由竖线字符分隔的任何一个元素。模式: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 )
- 如果指定的捕获名称匹配,则匹配为yes
; 否则,匹配可选的no
。模式:(?< quoted>")?(?(quoted).+?"|\S+\s)
,则Dogs.jpg
,"Yiska playing.jpg"
匹配"Dogs.jpg "Yiska playing.jpg""