StringTools
WildcardMatch
match strings against glob-style patterns
Calling Sequence
Parameters
Description
Examples
WildcardMatch( pattern, text )
pattern
-
Maple string
text
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 (). It can be a simple list of characters, such as aeiou, 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.
with⁡StringTools:
WildcardMatch⁡a*b,ab
true
WildcardMatch⁡a*b,acb
WildcardMatch⁡a*b,accccb
WildcardMatch⁡a*b,acccc
false
WildcardMatch⁡a?b,ab
WildcardMatch⁡a?b,acb
WildcardMatch⁡a?b,acc
WildcardMatch⁡a?b,accb
WildcardMatch⁡[a-eg-z],u
WildcardMatch⁡[a-z],U
WildcardMatch⁡[^a-z],U
WildcardMatch⁡[a--],-
WildcardMatch⁡[---],-
WildcardMatch⁡[-],-
WildcardMatch⁡[-xyz],-
WildcardMatch⁡[]],]
WildcardMatch⁡x[]abc],x]
WildcardMatch⁡x[ab]c],x]
Escape the opening square bracket ([) in the pattern using two backslashes to interpret it as a normal character.
WildcardMatch⁡x\\[ab]y,x[ab]y
See Also
searchtext
string
StringTools[RegMatch]
StringTools[Search]
Download Help Document