match strings against glob-style patterns - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Names and Strings : StringTools Package : Pattern Matching : StringTools/WildcardMatch

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 (). 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 az matches any lowercase letter, and 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, [^09] 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.

• 

Pattern matching facilities provided by the StringTools package include regular expression matching (see StringTools[RegMatch]) and fast string search (see StringTools[Search] and searchtext).

Examples

withStringTools:

WildcardMatcha*b,ab

true

(1)

WildcardMatcha*b,acb

true

(2)

WildcardMatcha*b,accccb

true

(3)

WildcardMatcha*b,acccc

false

(4)

WildcardMatcha?b,ab

false

(5)

WildcardMatcha?b,acb

true

(6)

WildcardMatcha?b,acc

false

(7)

WildcardMatcha?b,accb

false

(8)

WildcardMatch[a-eg-z],u

true

(9)

WildcardMatch[a-z],U

false

(10)

WildcardMatch[^a-z],U

true

(11)

WildcardMatch[a--],-

true

(12)

WildcardMatch[---],-

true

(13)

WildcardMatch[-],-

true

(14)

WildcardMatch[-xyz],-

true

(15)

WildcardMatch[]],]

true

(16)

WildcardMatchx[]abc],x]

true

(17)

WildcardMatchx[ab]c],x]

false

(18)

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

WildcardMatchx\[ab]y,x[ab]y

true

(19)

See Also

searchtext, string, StringTools, StringTools[RegMatch], StringTools[Search]


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam