Pattern Matching
The pattern-matching feature allow you to use wildcard characters, character lists, or character ranges, in any combination, to match strings. The following table shows the characters allowed in pattern and what they match:
Characters in pattern |
Matches in string |
? | Any single character. |
* | Zero or more characters. |
# | Any single digit (09). |
[charlist] | Any single character in charlist. |
[!charlist] | Any single character not in charlist. |
A group of one or more characters (charlist) enclosed in brackets ([ ]) can be used to match any single character in string and can include almost any character, including digits.
Important rules
- To match the special characters question mark (?), asterisk (*), number sign (#), and left bracket ([), enclose them in brackets. The right bracket (]) can't be used within a group to match itself, but it can be used outside a group as an individual character.
- An exclamation mark (!) at the beginning of charlist means that a match is made if any character except the characters in charlist is found in string. When used outside brackets, the exclamation mark matches itself.
- A hyphen (-) can appear either at the beginning (after an exclamation mark if one is used) or at the end of charlist to match itself. In any other location, the hyphen is used to identify a range of characters.
- When a range of characters is specified, they must appear in ascending sort order (from lowest to highest). [A-Z] is a valid pattern, but [Z-A] is not.
- The character sequence [] is considered a zero-length string ("").