Alternation constructs modify a regular expression to enable either/or matching. The following table lists the alternation constructs:
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 nopart. 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"" |
No comments:
Post a Comment