regexp.5 (2010 09)
r
regexp(5) regexp(5)
Patterns Matching Multiple Characters
The following rules may be used to construct patterns matching multiple characters from patterns match-
ing a single character:
* The asterisk (*) is a pattern that matches any string, including the null string.
RERE The concatenation of patterns matching a single character is a valid pattern that
matches the concatenation of the single characters or collating elements matched by
each of the concatenated patterns. For example, the pattern
a[bc] matches the
string
ab and ac.
The concatenation of one or more patterns matching a single character with one or
more asterisks is a valid pattern. In such patterns, each asterisk matches a string
of zero or more characters, up to the first character that matches the character fol-
lowing the asterisk in the pattern.
For example, the pattern
a*d matches the strings
ad, abd, and abcd; but not the
string
abc. When an asterisk is the first or last character in a pattern, it matches
zero or more characters that precede or follow the characters matched by the
remainder of the pattern. For example, the pattern
a*d* matches the strings ad,
abcd, abcdef, aaaad, and adddd
; the pattern *a*d matches the strings ad,
abcd, efabcd, aaaad, and adddd
.
Rule Qualification for Patterns Used for Filename Expansion
The rules described above for pattern matching are qualified by the following rules when the pattern
matching notation is used for filename expansion by sh(1), csh(1), ksh(1), and make(1).
If a filename (including the component of a pathname that follows the slash (
/) character) begins
with a period (.), the period must be explicitly matched by using a period as the first character of
the pattern; it cannot be matched by either the asterisk special character, the question mark special
character, or a bracket expression. This rule does not apply to make(1).
The slash character in a pathname must be explicitly matched by using a slash in the pattern; it
cannot be matched by either the asterisk special character, the question mark special character, or
a bracket expression. For make (1) only the part of the pathname following the last slash character
can be matched by a special character. That is, all special characters preceding the last slash char-
acter lose their special meaning.
Specified patterns are matched against existing filenames and pathnames, as appropriate. If the
pattern matches any existing filenames or pathnames, the pattern is replaced with those filenames
and pathnames, sorted according to the collating sequence in effect. If the pattern does not match
any existing filenames or pathnames, the pattern string is left unchanged.
If the pattern begins with a tilde (˜) character, all of the ordinary characters preceding the first
slash (or all characters if there is no slash) are treated as a possible login name. If the login name is
null (i.e., the pattern contains only the tilde or the tilde is immediately followed by a slash), the tilde
is replaced by a pathname of the process’s home directory, followed by a slash. Otherwise, the com-
bination of tilde and login name are replaced by a pathname of the home directory associated with
the login name, followed by a slash. If the system cannot identify the login name, the result is
implementation-defined. This rule does not apply to sh(1) or make(1).
If the pattern contains a
$ character, variable substitution can take place. Environmental variables
can be embedded within patterns as:
$name
or:
${name}
Braces are used to guarantee that characters following name are not interpreted as belonging to
name. Substitution occurs in the order specified only once; that is, the resulting string is not exam-
ined again for new names that occurred because of the substitution.
Rule Qualification for Patterns Used in the case Command
The rules described above for pattern matching are qualified by the following rule when the pattern
matching notation is used in the case command of sh(1) and ksh(1).
HP-UX 11i Version 3: September 2010 − 7 − Hewlett-Packard Company 7