RegExp pattern - alternation (Definition)

Sometimes you will want to match either one pattern or another using alternatives.


ECMAScript edition - 3

You can group sub-expressions and offer them as alternatives. For example, you might want to match "AB" or "CD". The alternation operator can be placed between each sub-expression to indicate choices like this:


This technique can be used in combinations with character literals, classes and repetition operators. Like this:


This matches with three lower case letters or 40 numeric digits and nothing else will match.

See also:RegExp pattern, RegExp pattern - character class, RegExp pattern - character literal, RegExp pattern - repetition


ECMA 262 edition 3 - section - 15.10.1

ECMA 262 edition 3 - section -

ECMA 262 edition 3 - section -