411 REFERENCE · Wikibooks
Regular Expressions/operator/pipe
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
A pipe symbol allows regular expression components to be logically ORed. For example, the following regular expression matches lines that start with the word "Germany" or the word "Netherlands". Note that parentheses are used to group the two expressive components.
/(^Germany)|(^Netherlands)/
Precedence
The alternation operator has a low precedence within a regular expression, so applies to the largest possible components either side:
Note that parentheses can be used to override the precedence to change the behaviour of the above expression:
The alternation operator is not recognized by some Unix tools
Some Unix tools do not recognize the pipe symbol as an alternation operator.