Alternation


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.

Initial Conditions
en-au
en-ca
en-ie
en-jm
en-nz
en-za
en-gb
en-us
COMMANDTop1:1
/au\|ca

As a simple example, lets first demonstrate how to select either of the literal strings "au" or "ca":

au\|ca
Simple alternate
en-au
en-ca
en-ie
en-jm
en-nz
en-za
en-gb
en-us
NORMALTop1:4
 

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:

Nested alternate
en-au
en-ca
en-ie
en-jm
en-nz
en-za
en-gb
en-us
NORMAL22%2:4