The pattern matching codes |{set} and |[set] contain a user-definable “pattern set”. This is analogous to an “OR” operator — the match is successful if the text matches the first item OR the second item OR the third item, etc. Each item in the pattern set can itself be a search string. The items are separated from each other by commas “,”. Commas themselves are represented by "|,".

For example, the search string to find any of the animal names “CAT”, “DOG”, “LION” or “MOUSE” is:

|{CAT,DOG,LION,MOUSE}

Pattern sets are very useful when searching for alternative words. Unfortunately, pattern sets execute more slowly than other searches — in this example, the pattern set has to be checked for each character in the text.


As another example, we want to search for occurrences of the words “automation” and “automobile”. We could, of course, place the entire words into a pattern set. As an alternative, we will just place the word endings into a pattern set in the following search string:

auto|{mation,mobile}

Since the pattern set is only checked when “auto” has already been found, this search will run very quickly.

The following search strings will find a vowel or a consonant:

|{a,e,i,o,u} - vowels |{b,c,d,f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,x,y,z} - consonants |!|{a,e,i,o,u,_,|d,|s} - consonants


The pattern matching code |[set] matches one optional occurrence (i.e. zero or one occurrence) of any item in the pattern set. For example, the following search string:

the |[tall,short,fat,thin] man

matches “the man”, “the tall man”, “the short man”, “the fat man” and “the thin man”. However, the string:

the |{tall,short,fat,thin} man

would not match just “the man”.

Pattern sets may be embedded within each other for even more sophisticated searching. For example, the revised search string:

the |{tall|[ish],short|[ish],fat,thin} man

also matches “the tallish man”, “the shortish man”, but not “the man”. The search string:

|{|{foot,basket,base}ball,soccer,golf,hockey}

matches “football”, “basketball”, “baseball”, “soccer”, “golf” and “hockey”.


The following search strings find numbers between one and four digits in length. They illustrate that there often are several equivalent ways to use pattern sets:

|{|d|d|d|d,|d|d|d,|d|d,|d} |{|d|[|d]|[|d]|[|d]} |{|d|[|d|[|d|[|d]]]}

Items that are substrings of another item must be placed after the larger item inside a pattern set.

Related Resources