Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Core Language > String Manipulation > String Operations >

StringMatchQ

StringMatchQ["string", patt]
tests whether "string" matches the string pattern patt.
StringMatchQ["string", RegularExpression["regex"]]
tests whether "string" matches the specified regular expression.
StringMatchQ[{s1, s2, ...}, p]
gives the list of results for each of the si.
  • StringMatchQ allows both ordinary StringExpression string patterns, as well as abbreviated string patterns containing the following metacharacters:
*zero or more characters
@one or more characters, excluding uppercase letters
\\*, etc.literal *, etc.
  • Verbatim["p"] specifies the verbatim string "p", with * and @ treated literally.
Test whether a string pattern matches a particular string:
Use abbreviated string patterns:
Test whether a string pattern matches a particular string:
In[1]:=
Click for copyable input
Out[1]=
 
Use abbreviated string patterns:
In[1]:=
Click for copyable input
Out[1]=
Use string patterns:
Use a regular expression:
Use pattern matching for dates:
Mixed regular expressions and string patterns:
StringMatchQ automatically threads over lists of strings:
With IgnoreCase -> True, uppercase and lowercase are treated the same:
The option SpellingCorrection -> True allows automatic spelling correction:
Find all words that contain double letters:
For literal strings, SameQ is equivalent to StringMatchQ:
For fast extraction of elements in a list, use Pick:
Compare to Select:
Use StringFreeQ to check no substring matches a pattern:
StringMatchQ returns False whenever StringFreeQ is True:
StringMatchQ does not work on strings with embedded formatting information:
Spelling correction only works for letter string patterns:
New in 1 | Last modified in 5.1
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team