HP-UX Reference (11i v1 05/09) - 5 Miscellaneous Topics (vol 9)
r
regexp(5) regexp(5)
^ The circumflex is special except when used in a bracket expression in a non-leading
position.
delimiter Any character used to bound (i.e., delimit) an entire ERE is special for that ERE.
Period
A period ( . ), when used outside of a bracket expression, is an ERE that matches any printable or nonprint-
able character except <newline>.
ERE Bracket Expression
The syntax and rules for ERE bracket expressions are the same as for RE bracket expressions found above.
EREs Matching Multiple Characters
The following rules may be used to construct EREs matching multiple characters from EREs matching a
single character:
RE RE A concatenation of EREs matches the first encountered concatenation of the strings
matched by each component of the ERE. Such a concatenation of EREs enclosed in
parentheses matches whatever the concatenation without the parentheses matches.
For example, both the ERE bc and the ERE (bc) matches the second and third char-
acters of the string abcdefabcdef. The longest overall string is matched.
RE+ The special character plus ( +), when following an ERE matching a single character, or
a concatenation of EREs enclosed in parenthesis, is an ERE that matches one or more
occurrences of the ERE preceding the plus sign. The string matched will contain as
many occurrences as possible. For example, the ERE b+c matches the fourth through
seventh characters in the string acabbbcde.
RE∗∗ The special character asterisk ( ∗∗ ), when following an ERE matching a single charac-
ter, or a concatenation of EREs enclosed in parenthesis, is an ERE that matches zero
or more occurrences of the ERE preceding the asterisk. For example, the ERE b∗∗c
matches the first character in the string cabbbcde. If there is any choice, the longest
left-most string that permits a match is chosen. For example, the ERE b∗∗cd matches
the third through seventh characters in the string cabbbcdebbbbbbcdbc.
RE? The special character question mark ( ? ), when following an ERE matching a single
character, or a concatenation of EREs enclosed in parenthesis, is an ERE that
matches zero or one occurrences of the ERE preceding the question mark. The string
matched will contain as many occurrences as possible. For example, the ERE b?c
matches the second character in the string acabbbcde.
RE{m,n} interval expression that functions the same way as basic regular expression syntax,
RE\{m,n\}
Alternation
Two EREs separated by the special character vertical bar (|) matches a string that is matched by either
ERE. For example, the ERE ((ab)|c)d matches the string abd and the string cd. A vertical bar ’|’ may
not appear as follows:
may not appear first or last in an ERE.
may not appear immediately following a vertical bar.
may not appear after a left parenthesis.
may not appear immediately preceding a right parenthesis.
Precedence
The order of precedence is as follows, from high to low:
[] square brackets
∗∗ +? asterisk, plus sign, question mark
^$ anchoring
concatenation
| alternation
HP-UX 11i Version 1: September 2005 − 5 − Hewlett-Packard Company Section 5−−303