Show/Hide Toolbars

Alternation constructs modify a regular expression to enable either/or matching. These constructs include the language elements listed in  table 1.

Alternation construct

Description

|

Matches any one element separated by the vertical bar (|) character.

(?( expression )yes | no )

Matches yes if the regular expression pattern designated by expression matches; otherwise, matches the optional no part.expression is interpreted as a zero-width assertion.

(?( name ) yes |no )

Matches yes if name, a named or numbered capturing group, has a match; otherwise, matches the optional no.

Table 1: Alternation constructs

Pattern

Matches

th(e|is|at)

"the", "this" in "this is the day. "

(?(A)A\d{2}\b|\b\d{3}\b)

"A10", "910" in "A10 C103 910"

(?<quoted>")?(?(quoted).+?"|\S+\s)

Dogs.jpg, "Yiska playing.jpg" in "Dogs.jpg "Yiska playing.jpg""

Table 2: Examples for alternation constructs

© 2021 AFRY Austria GmbH, www.redbex.com