HP-UX Reference (11i v1 05/09) - 5 Miscellaneous Topics (vol 9)

r
regexp(5) regexp(5)
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 following
the asterisk in the pattern.
For example, the pattern ad 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 ad matches the strings ad,
abcd, abcdef, aaaad, and adddd; the pattern ad 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 pat-
tern; it cannot be matched by either the asterisk special character, the question mark special charac-
ter, 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 can-
not 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 character
lose their special meaning.
Specified patterns are matched against existing filenames and pathnames, as appropriate. If the pat-
tern 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 combina-
tion 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 match-
ing notation is used in the case command of sh(1) and ksh(1).
Multiple alternative patterns in a single clause can be specified by separating individual patterns with
the vertical bar character ( |); strings matching any of the patterns separated this way will cause the
corresponding command list to be selected.
SEE ALSO
ksh(1), sh(1), fnmatch(3C), glob(3C), regcomp(3C), setlocale(3C), environ(5).
STANDARDS CONFORMANCE
<
regexp.h>: AES, SVID2, SVID3, XPG2, XPG3, XPG4
HP-UX 11i Version 1: September 2005 7 Hewlett-Packard Company Section 5305