WildcardMatch - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.

Online Help

All Products    Maple    MapleSim


StringTools

  

WildcardMatch

  

match strings against glob-style patterns

 

Calling Sequence

Parameters

Description

Examples

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 [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

> 

with⁡StringTools:

> 

WildcardMatch⁡a*b,ab

true

(1)
> 

WildcardMatch⁡a*b,acb

true

(2)
> 

WildcardMatch⁡a*b,accccb

true

(3)
> 

WildcardMatch⁡a*b,acccc

false

(4)
> 

WildcardMatch⁡a?b,ab

false

(5)
> 

WildcardMatch⁡a?b,acb

true

(6)
> 

WildcardMatch⁡a?b,acc

false

(7)
> 

WildcardMatch⁡a?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)
> 

WildcardMatch⁡x[]abc],x]

true

(17)
> 

WildcardMatch⁡x[ab]c],x]

false

(18)

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

true

(19)

See Also

searchtext

string

StringTools

StringTools[RegMatch]

StringTools[Search]