Regular Expression Syntax and Usage

A regular expression consists of a combination of ordinary and special characters, and bracket expressions. Together, these elements can be used to specify a search expression with flexibility and power far greater than that afforded by a simple text search.

Simple regular expressions can be specified in the Live Find search facility. To specify more elaborate regular expressions, use the Editor - Find and Replace dialog window.

Regular Expression Character Set
You can use any single-byte character in your regular expression, subject to the rules listed below:

 

Bracket Expressions
A bracket expression can contain one or more expressions that match characters, collating symbols, equivalence or character classes, or ranges of characters. Bracket expressions are case-sensitive only if you select the Case-sensitive check-box in the Editor - Find and Replace window.

The basic forms of a bracket expression are:

Valid in: Expression Description
Find and Replace Live Find
yes yes
[string]
Matches any of the characters specified in string. For example, [set] matches the next instance of characters s, e, or t.
yes yes
[^string]
Does not match any of the characters specified in string.
yes yes
[symbol1-symbol2]
Matches all collating elements that fall between the two specified collating symbols, inclusive. The symbols must be different, with symbol2 higher in the collating sequence than symbol1. For example, [d-f] will match the next instance of characters d, e, or f.

Note: If you want to match a hyphen (-), the hyphen must appear as either the first or last character in the string.

Note: You can use a right bracket (]) as an ordinary character in a bracket expression only if you specify it as the first character following the left bracket ([) or caret (^) symbols.

 

Regular Expression Syntax
You can combine characters, special characters, and bracket expressions to form regular expressions that match multiple characters and character patterns. Basic syntax elements for regular expressions are described below.

Valid in: Expression Syntax Description
Find and Replace Live Find
yes no
(expr) 
Matches expr. Place a simple expression in parentheses if you want to apply a +, |, or * operator or { } pattern repetition expression to it.
yes yes
expr*
Matches zero or more occurrences of the pattern specified by expr.

For example, in the phrase:

at the cabana

[abc]* matches any single character in your file, as well as all complete sequences of letters including only the letters a, b, or c, as in the character sequence caba.

When specified from the Find and Replace dialog window, subsequent find operations start from the character immediately following the first character of the found string. For example, in the phrase above, after a find operation finds caba, subsequent find operations would find aba, ba, and a,

When specified using the Live Find facility, subsequent find operations start from the first character immediately following the entire found string. For example, in the phrase above, after a find operation finds caba, the next find would start with the letter n in the word cabana.

yes yes
expr{n}
Matches exactly n occurrence(s) of the pattern specified by expr.

For example, in the phrase:

at the cabana

When specified from the Find and Replace dialog window, [cab]{2} matches only the sequences ca, ab, and ba in the word cabana.

[cab]{3} would match the sequences cab and aba in the word cabana.

When specified using the Live Find facility, [cab]{2} matches only the sequences ca and ba in the word cabana.

[cab]{3} would match the sequence cab in the word cabana.

yes yes
expr{n,}
Matches at least n occurrences of the pattern specified by expr.

For example, in the phrase:

at the cabana

When specified from the Find and Replace dialog window, [cab]{3,} matches only the sequences caba and aba in the word cabana, but not ca, ab, or ba.

When specified using the Live Find facility, [cab]{3,} matches only the sequence caba in the word cabana.

For example, when a find operation encounters the word:

banana

(abc){1,) initially matches anan. A subsequent find operation will match the last an character sequence in the same word.

yes yes
expr{n1,n2}
Matches between n1 and n2 occurrence(s) of the pattern specified by expr and occurrences between n1 and n2.

For example, in the phrase:

at the cabana

When specified from the Find and Replace dialog window, [cab]{2,3} matches only the sequences cab, aba, and ba in the word cabana, but not c, a, b, or caba.

When specified using the Live Find facility, [cab]{2,3} matches only the sequences cab in the word cabana.

yes yes
^expr
Matches the pattern specified by expr only if it occurs at the very start of a line.
yes yes
expr$
Matches the pattern specified by expr only if it occurs at the very end of a line.
yes yes
^expr$
Matches the pattern specified by expr only if it comprises the entire line.
yes no
expr?
Matches zero or more occurrences of the pattern specified by expr.
yes no
expr+
Matches one or more occurrences of the pattern specified by expr.
yes no
expr1 | expr2
Matches the pattern specified by either expr1 or expr2. For example, s|o matches both characters s and o.

 

Operator Orders of Precedence
Regular expression elements are processed in a specific order. The order of precedence is described below. Element categories with higher precedence appear closer to the top of the list. Within each category, higher precedence is to the left. Not all operators apply to the Live Find facility.

Operators Category or Description
\special
Special characters preceded by a backslash
[
Bracket expressions
( )
Grouping of expressions
* + ? {n} {n,} {n1,n2}
Pattern repetition
(none)
Concatenation of expressions
^ $
Anchoring of pattern to start or end of line
|
Alternate match patterns


Finding Text
Find and Replace Text