If it often helpful for patterns to allow multiple atoms to match in a specific location. In patterns, this concept is often called "alternation", or the ability to have alternate atoms match in a particular location.
Alternatives are specified by separating them with "|":
Pattern | Matches |
---|---|
(a|b) | a or b |
(a|b|c) | a, b, or c |
where a, b, and c represent any atoms. Atoms are evaluated from left to right, and first match is returned.
Lets demonstrate how to use alternation with the following buffer, which contains a list of English language codes.
As a simple example, lets first demonstrate how to select either of the literal strings "au" or "ca":
au\|ca
Next, lets try an example with nested alternation. Suppose we want to select a literal "au" or any other code that ends with "a" or "m". We start by creating the nested alternation:
\w\(a\|m\)
then create the outer alternation:
au\|\w\%(a\|m\)
and finally execute the search: