WildcardMatch - Maple Help

StringTools

 WildcardMatch
 match strings against glob-style patterns

 Calling Sequence WildcardMatch( pattern, text )

Parameters

 pattern - Maple string text - Maple string

Description

 • The WildcardMatch(pattern, text) command provides glob-style pattern matching. Given a pattern containing wildcards, and an input string text, WildcardMatch returns the value true if the given text matches the pattern, and returns the value false otherwise.
 • The wildcards are similar to those used in filename globbing in UNIX shells. These are defined as follows.

 * matches zero or more characters ? matches one character [ccl] matches any character in the character class ccl

 • Character classes denote sets of characters to match. A character class is enclosed in square brackets ($\left[\right]$). It can be a simple list of characters, such as $\left[\mathrm{aeiou}\right]$, which matches any of the characters $"a"$, $"e"$, $"i"$, $"o"$ or $"u"$. Character classes can include character ranges, which are defined by their order in the US-ASCII character encoding. For example, the character class [a-z] matches any lowercase letter, and [0-9] matches any digit. A character class can be negated (or complemented) by including the character $^$ as the first within the character class. Thus, for instance, $[^0-9]$ denotes the set of characters other than the digits. The "^" character has this special complementing meaning only when it appears as the first character in a character class. If it appears elsewhere, then it stands for itself. To include a hyphen character "-" in a character class, write it as the first character in the character class, or include it in a character range. To include the character "]" in a character class, write it as the first character following the opening bracket, or include it in a character range. If you want to exclude the character "]" from a character class, write it as the first character after the "^" as, for example, in "[^]]".
 • Pattern matching facilities provided by the StringTools package include regular expression matching (see StringTools[RegMatch]) and fast string search (see StringTools[Search] and searchtext).
 • All of the StringTools package commands treat strings as (null-terminated) sequences of $8$-bit (ASCII) characters.  Thus, there is no support for multibyte character encodings, such as unicode encodings.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{WildcardMatch}\left("a*b","ab"\right)$
 ${\mathrm{true}}$ (1)
 > $\mathrm{WildcardMatch}\left("a*b","acb"\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{WildcardMatch}\left("a*b","accccb"\right)$
 ${\mathrm{true}}$ (3)
 > $\mathrm{WildcardMatch}\left("a*b","acccc"\right)$
 ${\mathrm{false}}$ (4)
 > $\mathrm{WildcardMatch}\left("a?b","ab"\right)$
 ${\mathrm{false}}$ (5)
 > $\mathrm{WildcardMatch}\left("a?b","acb"\right)$
 ${\mathrm{true}}$ (6)
 > $\mathrm{WildcardMatch}\left("a?b","acc"\right)$
 ${\mathrm{false}}$ (7)
 > $\mathrm{WildcardMatch}\left("a?b","accb"\right)$
 ${\mathrm{false}}$ (8)
 > $\mathrm{WildcardMatch}\left("\left[a-eg-z\right]","u"\right)$
 ${\mathrm{true}}$ (9)
 > $\mathrm{WildcardMatch}\left("\left[a-z\right]","U"\right)$
 ${\mathrm{false}}$ (10)
 > $\mathrm{WildcardMatch}\left("\left[^a-z\right]","U"\right)$
 ${\mathrm{true}}$ (11)
 > $\mathrm{WildcardMatch}\left("\left[a--\right]","-"\right)$
 ${\mathrm{true}}$ (12)
 > $\mathrm{WildcardMatch}\left("\left[---\right]","-"\right)$
 ${\mathrm{true}}$ (13)
 > $\mathrm{WildcardMatch}\left("\left[-\right]","-"\right)$
 ${\mathrm{true}}$ (14)
 > $\mathrm{WildcardMatch}\left("\left[-xyz\right]","-"\right)$
 ${\mathrm{true}}$ (15)
 > $\mathrm{WildcardMatch}\left("\left[\right]\right]","\right]"\right)$
 ${\mathrm{true}}$ (16)
 > $\mathrm{WildcardMatch}\left("x\left[\right]abc\right]","x\right]"\right)$
 ${\mathrm{true}}$ (17)
 > $\mathrm{WildcardMatch}\left("x\left[ab\right]c\right]","x\right]"\right)$
 ${\mathrm{false}}$ (18)

Escape the opening square bracket ([) in the pattern using two backslashes to interpret it as a normal character.

 > $\mathrm{WildcardMatch}\left("x\\\left[ab\right]y","x\left[ab\right]y"\right)$
 ${\mathrm{true}}$ (19)