Regex alternation is syntax that allows a match to satisfy one of multiple alternative pattern branches.
Alternation uses the pipe character (|) to match one of several alternatives. Parentheses can group alternatives so another operator applies to the group. section 12.2.2
Alternatives in a repeated group
The pattern /(ab|cd)+/ matches ab, cd, abcd, and cdab, but not acbd: each repetition must match either ab or cd. section 12.2.2
How Secrets of the JavaScript Ninja, Third Edition covers it
How deep it goes
Defines pipe syntax and demonstrates grouped alternatives under repetition, without detailing evaluation internals.
Examples
Uses /a|b/ and /(ab|cd)+/ to contrast single-character choices with repeated grouped alternatives.
What you can do after
Evaluate whether a string fits a simple alternative or repeated grouped alternatives.
How it connects
Combines with grouping and repetition operators in regular expressions.
regular expressionuses · A regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
set unionproduces · Set union is the operation that produces a set containing every element belonging to at least one of its operand sets.
lookbehind assertionuses · A lookbehind assertion is a regular-expression assertion that checks whether a pattern matches before the current position without consuming the checked input.
logical ORequivalent to · Logical OR is a Boolean disjunction that is true when at least one of its component propositions is true.
This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Third Edition. The section links point to the parts of the book it draws on.