Name
MatchPattern -- check for a pattern match with a string (V2.0)
Synopsis
bool = MatchPattern(src$, pattern$)
Function
This function checks if the string specified in src$ matches the pattern specified in pattern$. If it does, True will be returned, else False. MatchPattern() will compare pattern$ to src$ character by character and abort as soon as it finds a difference. If it does not find a difference, it will return True.

The pattern specified in pattern$ is a string that can contain normal characters and wildcards. A wildcard is a special character that can be used to match more than one character in the source string. The following wildcards are currently supported:

*
Matches all characters.

?
Matches just a single character.

#
Matches all numbers.

[]
Matches one or several characters or a range of characters if delimited using a hyphen. For example, [a] matches only a, whereas [af] matches a and f and [a-f] matches all characters in the range of a to f. You can use the '!' prefix to negate the result, i.e. [!a] matches every character except a.

You can also combine multiple patterns in a single string by separating them using a semicolon.

If you need more sophisticated pattern matching, have a look at the PatternFindStr() function. See PatternFindStr for details.

Inputs
src$
source string
pattern$
pattern to compare string with
Results
bool
True if string matches the pattern or False
Example
r = MatchPattern("Pictures/JPG/Pic1.jpg", "*.jpg")
Returns True because the string matches the pattern.


r = MatchPattern("Pictures/JPG/Pic1.gif", "*.jpg;*.gif")
Returns True because the string matches the pattern.


r = MatchPattern("Hollywood 2.a", "Hollywood #.#")
Returns False because a does not match the numeric wildcard (#).

Show TOC