Regular Expressions/operator/pipe

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 edit

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 edit

Some Unix tools do not recognize the pipe symbol as an alternation operator.