HP-UX Reference (11i v3 07/02) - 5 Miscellaneous Topics (vol 9)

r
regexp(5) regexp(5)
specification of EREs. The extended regular expression special characters and the contexts in which they
have their special meaning are:
.[\()*+?$|
The period, left square bracket, backslash, left parenthesis, right parenthesis, aster-
isk, plus sign, question mark, dollar sign, and vertical bar are special except when
used in a bracket expression (see ERE Bracket Expression).
^ 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:
ERE ERE 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
characters of the string abcdefabcdef . The longest overall string is matched.
ERE+ 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.
ERE* 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 long-
est 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
.
ERE
? 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 .
ERE{m,n} interval expression that functions the same way as basic regular expression syntax,
ERE\{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.
HP-UX 11i Version 3: February 2007 5 Hewlett-Packard Company 407