The STRMATCH function compares its search string, which can contain wildcard characters, against the input string expression. The result is an array with the same structure as the input string expression. Those elements that match the corresponding input string are set to True (1), and those that do not match are set to False (0).

The wildcards understood by STRMATCH are similar to those used by the standard UNIX shell:


Wildcard Character



Matches any string, including empty strings.


Matches any single character.


Matches any one of the enclosed characters. A pair of characters separated by “-” matches any character lexically between the pair, inclusive. If the first character following the opening [ is a !, any character not enclosed is matched.

To prevent one of these characters from acting as a wildcard, precede it with a backslash character (e.g. "\*" matches the asterisk character). Quoting any other (non-wildcard) character (including \ itself) is equivalent to the character (e.g. "\a" is the same as "a").


See Additional Examples for more information on using STRMATCH.

Example 1

Find all 4-letter words in a string array that begin with “f” or “F” and end with “t” or “T”:

str = ['foot', 'Feet', 'fate', 'FAST', 'ferret', 'fort'] 
PRINT, str[WHERE(STRMATCH(str, 'f??t', /FOLD_CASE) EQ 1)]

This results in:

foot Feet FAST fort

Example 2

Find words of any length that begin with “f” and end with “t”:

str = ['foot', 'Feet', 'fate', 'FAST', 'ferret', 'fort']
PRINT, str[WHERE(STRMATCH(str, 'f*t', /FOLD_CASE) EQ 1)]

This results in:

foot Feet FAST ferret fort


Result = STRMATCH( String, SearchString [, /FOLD_CASE] )

Return Value

Returns 1 if the pattern specified by SearchString exists in String, or 0 otherwise. If the String argument contains an array of strings, the result is an array of 1s and 0s with the same number of elements as String, indicating which elements contain SearchString.



A scalar string or string array to be searched.


A scalar string containing the pattern to search for in String. The pattern string can contain wildcard characters as discussed above.



The comparison is usually case sensitive. Setting the FOLD_CASE keyword causes a case insensitive match to be done instead.

Additional Examples

Example 3

Find 4-letter words beginning with “f” and ending with “t”, with any combination of “o” and “e” in between:

str = ['foot', 'Feet', 'fate', 'FAST', 'ferret', 'fort']
PRINT, str[WHERE(STRMATCH(str, 'f[eo][eo]t', /FOLD_CASE) EQ 1)]

This results in:

foot Feet

Example 4

Find all words beginning with “f” and ending with “t” whose second character is not the letter “o”:

str = ['foot', 'Feet', 'fate', 'FAST', 'ferret', 'fort']
PRINT, str[WHERE(STRMATCH(str, 'f[!o]*t', /FOLD_CASE) EQ 1)]

This results in:

Feet FAST ferret

Version History



See Also

String Operations, String Processing, STRCMP, STRJOIN, STREGEX, STRMID, STRPOS, STRSPLIT


This page has no user notes yet. Be the first one!

This information is not subject to the controls of the International Traffic in Arms Regulations (ITAR) or the Export Administration Regulations (EAR). However, it may be restricted from transfer to various embargoed countries under U.S. laws and regulations.
© 2014 Exelis Visual Information Solutions