Wildcards for Text
Wildcard | Description |
---|---|
* | No or several characters. |
? | Any single character. |
# | Any single numeral (0 - 9). |
[charlist] | Any single character in charlist. |
[!charlist] | Any single character that isn't contained in charlist. |
The wildcards can be combined in any sequence.
The following characters have to be inserted in square brackets in order to be used for a compare operation: left square bracket ([), question mark (?), pound sign (#) and asterisk (*). The right square bracket (]) can't be used in a string of characters being compared. However, it can be indicated outside of a string as an individual character.
You can also specify a range of characters in charlist by indicating the largest and smallest value of the range, separated by a hyphen (-). For example, [A-Z] results in a match if the respective character position in charlist is a letter between A and Z. You can specify a sequence of several ranges in square brackets without using separators.
Other key rules for using wildcards:
- An exclamation point (!) at the beginning of charlist means that a match results when any character except for the characters in charlist is found. If the exclamation point is used outside of the square brackets it serves as a wildcard for itself.
- A hyphen (-) can appear at the beginning (after an exclamation point, if present) or at the end of charlist in order to serve as a wildcard for itself. In any other position a hyphen serves to designate a character range.
- When a range of characters is specified, the characters have to be listed in ascending order (from the lowest to the highest). This means that [A-Z] is a permissible pattern whereas [Z-A] isn't.
Examples:
Type of correspondence | Text | Correspondence | No correspondence |
---|---|---|---|
Several characters | a*a | aa, aBa, aBBBa | aBC |
*ab* | abc, AABB, Xab | aZb, bac | |
[ ? # * | a[*]a | a*a | aaa |
Several characters | ab* | abcdefg, abc | cab, aab |
Individual characters | a?a | aaa, a3a, aBa | aBBBa |
Individual numerals | a#a | a0a, a1a, a2a | aaa, a10a |
Character range | [a-z] | f, p, j | 2, & |
Outside of range | [!a-z] | 9, &, % | b, a |
No numerals | [!0-9] | A, a, &, ~ | 0, 1, 9 |
Combination | a[!b-m]# | An9, az0, a99 | abc, aj0 |