Open System Services Shell and Utilities Reference Manual (G06.29+, H06.08+, J06.03+)
egrep(1) OSS Shell and Utilities Reference Manual
• A regular expression followed by a + (plus sign) matches one or more occurrences of the
regular expression.
• A regular expression followed by a ? (question mark) matches zero or one occurrence of
the regular expression.
• Two regular expressions separated by a | (vertical bar) or by a newline character match
either expression.
• A regular expression can be enclosed in ()(parentheses) for grouping.
The order of precedence of operators is as follows:
• [= =] [: :] [. .] (collation-related bracket symbols)
• \<special_c haracter> (escaped characters)
• [](bracket expressions)
• ()(grouping)
• *+?{m, n} (single-character-ERE duplication)
• concatenation
• ˆ$(anchoring)
• | (alternation)
Regular Expressions (REs)
Regular expressions (REs) cannot contain newline characters, because these signal a new pattern.
The following REs match a single character:
character
An ordinary character (one other than one of the special pattern-matching characters)
matches itself.
. A . (dot) matches any single character except the newline character.
[string] A string enclosed in [](brackets) matches any one character in that string. In addition,
certain pattern-matching characters have special meanings within brackets:
^ If the first character of string is a ˆ (circumflex), the RE [ˆstring] matches any
character except the characters in string and the newline character. A ˆ has
this special meaning only if it occurs first in the string.
- You can use a - (dash) to indicate a range of consecutive characters. The char-
acters that fall within a range are determined by the current collating
sequence, which is defined by the LC_COLLATE environment variable. For
example, [a-d] is equivalent to [abcd] in the traditional ASCII collating
sequence.
A range can include a multicharacter collating element enclosed within
bracket-period delimiters ([. .]). The bracket-period delimiters in the RE syn-
tax distinguish multicharacter collating elements from a list of the individual
characters that make up the element.
A collating sequence can define equivalence classes for characters. An
equivalence class is a set of collating elements that all sort to the same primary
location. They are enclosed within bracket-equal delimiters ([= =]). An
3−52
Hewlett-Packard Company 527188-021