Types of wildcard patterns
A wildcard pattern is a series
of characters that are matched against incoming character strings. You can use these patterns when you define pattern matching criteria.
Matching is done strictly from left to right, one character or basic wildcard
pattern at a time. Basic wildcard patterns are defined in
Basic wildcard patterns. Characters that are not part of match constructs match themselves. The pattern and the incoming string must match completely. For example, the pattern abcd does not match the input abcde or abc.
A compound wildcard pattern
consists of one or more basic wildcard patterns separated by ampersand (&) or tilde (~) characters. A compound wildcard pattern is matched by attempting to match each of its component basic wildcard patterns against
the entire input string. Compound wildcard patterns are listed in
Compound wildcard patterns.
If the first character of a compound wildcard pattern is an ampersand (&) or tilde (~) character, the compound is interpreted as if an asterisk (*) appeared at the beginning of the
pattern. For example, the pattern ~*[0-9]* matches any string that does not contain any digits. A trailing instance of an ampersand character (&) can only match the empty string. A trailing instance of a tilde character (~) can be read as “except
for the empty string.”
Spaces are interpreted as characters and are subject to matching even if they are adjacent to operators like “&”.
Character | Description |
|---|---|
? | Matches any single character. For example, server?.example.com matches server3.example.com and serverB.example.com, but not server10.example.com. |
* | Matches an arbitrary string of characters. The string can be empty. For example, server*.example.com
matches server-ny.example.com and server.example.com (an empty match). |
[set] | Matches any single character that appears within [set]; or, if the first character of [set] is (^), any single character that is
not in the set. A hyphen (-) within [set] indicates a range, so that [a-d] is equivalent to [abcd].
The character before the hyphen (-) must precede the character after it or the range will be empty. The character (^) in any position except the first, or a hyphen (-) at the first or last position, has no special meaning. For example, server[789-].example.com
matches server7.example.com through server9.example.com, but not server6.example.com. It also matches server-.example.com. For example, server[^12].example.com does not match server1.example.com or server2.example.com, but will match server8.example.com. |
<n1-n2> | Matches numbers in a given range. Both
n1 and
n2 must be strings of digits, which represent nonnegative integer values. The matching characters are a non-empty string of digits whose value, as a nonnegative integer, is greater than or equal to
n1 and less than or equal
to
n2 . If either end of the range is omitted, no limitation is placed on the accepted number.For example, 98.49.<1-100>.10 matches a range of IPv4 addresses from 98.49.1.10 through 98.49.100.10. Example of an omitted
high end of the range: <50->matches any string of digits with a value greater than or equal to 50. Example of an omitted low end of the range: <-150>matches any value between zero and 150. For a more subtle example: The pattern
<1-10>* matches 1, 2, up through 10, with * matching no characters. Similarly, it matches strings like 9x, with * matching the trailing x. However, it does not match 11, because <1-10>always extracts the longest possible string of digits
(11) and then matches only if the number it represents is in range. |
| | Matches alternatives. For example,”ab|bc|cd” without spaces matches exactly the three following strings: “ab”, “bc”, and “cd”. A | as the first or last character of a pattern accepts an empty string as a match. Example with spaces “ab |
bc” matches the strings “ab” and “ bc”. |
\ | Removes the special status,
if any, of the following character. Backslash (\) has no special meaning within a set ([set]) or range (<n1-n2>) construct. |
Special characters for compound wildcard patterns
are summarized in
Compound wildcard patterns.
Character | Description |
& | “And Also” for a compound wildcard pattern. If a component basic wildcard pattern is preceded by & (or is the first basic wildcard pattern
in the compound wildcard pattern), it
must successfully match. Example: *NY*&*Router* matches all strings that contain NY and also contain Router. Example: <1-100>&*[02468] matches even numbers between 1 and
100 inclusive. The <1-100>component only passes numbers in the correct range and the *[02468] component only passes numbers that end in an even digit. Example: *A*|*B*&*C* matches strings that contain either an A or a B, and also
contain a C. |
~ | “Except” for a compound wildcard pattern (opposite function
of &).If a component basic wildcard pattern is preceded by ~, it
must not match. Example: 10.20.30.*~10.20.30.50 matches all devices on network 10.20.30 except 10.20.30.50. Example: *Router*~*Cisco*&*10.20.30.*~10.20.30.<10-20>*
matches a Router, except a Cisco router, with an address on network 10.20.30, except not 10.20.30.10 through 10.20.30.20. |