Alternation (formal language theory)

In formal language theory and pattern matching, alternation is the union of two sets of strings, or equivalently the logical disjunction of two patterns describing sets of strings.

[1] In implementations of regular expressions, alternation is often expressed with a vertical bar connecting the expressions for the two languages whose union is to be matched,[2][3] while in more theoretical studies the plus sign may instead be used for this purpose.

[1] The ability to construct finite automata for unions of two regular languages that are themselves defined by finite automata is central to the equivalence between regular languages defined by automata and by regular expressions.

In formal language theory, alternation is commutative and associative.

This is not in general true of the form of alternation used in pattern-matching languages, because of the side-effects of performing a match in those languages.