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

represents an operator form of StringMatchQ that can be applied to an expression.

Details and Options

  • 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.
  • Setting the option IgnoreCase->True makes StringMatchQ treat lowercase and uppercase letters as equivalent.
  • Setting the option SpellingCorrection->True makes StringMatchQ allow strings to match even if a small fraction of their characters are different.
  • StringMatchQ[form][expr] is equivalent to StringMatchQ[expr,form].
  • StringMatchQ[BioSequence["type","seq"],patt] will match the string "seq" against patt. In this case, degenerate letters in patt are interpreted as wild-card patterns based on the type of bio sequence. Use Verbatim["patt"] to match degenerate letters literally.
  • If the bio sequence operated upon by StringMatchQ is circular, wraparound matches are possible.

Examples

open allclose all

Basic Examples  (3)

Test whether a string pattern matches a particular string:

Use abbreviated string patterns:

Use the operator form of StringMatchQ:

Scope  (9)

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:

Find whether a bio sequence will match a given pattern:

Find whether a bio sequence matches a degenerate pattern:

Circular sequences support wraparound matches:

Use Verbatim to avoid a degenerate match:

Options  (2)

IgnoreCase  (1)

With IgnoreCase -> True, uppercase and lowercase are treated the same:

SpellingCorrection  (1)

The option SpellingCorrection -> True allows automatic spelling correction:

Applications  (1)

Find all words that contain double letters:

Properties & Relations  (3)

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:

Possible Issues  (2)

StringMatchQ does not work on strings with embedded formatting information:

Spelling correction only works for letter string patterns:

Wolfram Research (1988), StringMatchQ, Wolfram Language function, https://reference.wolfram.com/language/ref/StringMatchQ.html (updated 2020).

Text

Wolfram Research (1988), StringMatchQ, Wolfram Language function, https://reference.wolfram.com/language/ref/StringMatchQ.html (updated 2020).

BibTeX

@misc{reference.wolfram_2021_stringmatchq, author="Wolfram Research", title="{StringMatchQ}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/StringMatchQ.html}", note=[Accessed: 23-July-2021 ]}

BibLaTeX

@online{reference.wolfram_2021_stringmatchq, organization={Wolfram Research}, title={StringMatchQ}, year={2020}, url={https://reference.wolfram.com/language/ref/StringMatchQ.html}, note=[Accessed: 23-July-2021 ]}

CMS

Wolfram Language. 1988. "StringMatchQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/StringMatchQ.html.

APA

Wolfram Language. (1988). StringMatchQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StringMatchQ.html