Go to: Synopsis. Return value. Related. MEL examples.

Synopsis

gmatch string string

gmatch is NOT undoable, NOT queryable, and NOT editable.

Returns a non-zero result if the pattern specified by the second argument matches the search string in the first argument.

gmatch provides shell-style pattern matching, also known as "glob" matching. There are three ways to specify wild cards in this type of matching and they are as follows:

* matches any string
? matches any single character
[...] Matches any one of the enclosed characters. "*" and "?" lose their special meanings between the brackets and simply match themselves. A pair of characters separated by "-" matches any character lexically between the pair, inclusive (e.g. "[0-9]" matches any digit). If the first character following the opening "[" is a "!" any character not enclosed is matched (e.g. "[!ab]" will match any character except "a" or "b"). A "-" can be included in the character set as itself by putting it as the first or last character.

The backslash character ("\") is used as an escape to make the character which follows it lose any special meaning it might have and just match itself. MEL also uses backslash as an escape in string literals for its special characters. This means that for gmatch to find a backslash in a literal string, it has to be doubled up. For example, to match "?" as just itself, the pattern string has to be "\\?", and to match "\" as itself, the pattern string has to be "\\\\".

Return value

intMatching value

Related

match, strcmp

MEL examples

gmatch "matches" "m*s";
// Result: 1 //
gmatch "matches" "mat*";
// Result: 1 //
gmatch "matches" "ma[a-z]ches";
// Result: 1 //
gmatch "matches" "ma[!a-m]ches";
// Result: 1 //
gmatch "matches" "ma?ches";
// Result: 1 //
gmatch "no match" "?atch";
// Result: 0 //