MatchQ

MatchQ[expr,form]

returns True if expr matches the pattern form, and returns False otherwise.

MatchQ[form]

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

Details

Examples

open allclose all

Basic Examples  (3)

Test if an expression is an integer:

Test if an expression is a sum of two or more terms:

Test if an expression is explicitly zero:

Scope  (10)

Match an association:

Match a rule in an association, using an association as a pattern:

KeyValuePattern lets you match any element in an association:

It also works on lists of rules:

Match a rule in an association with a condition:

Match a Rule in an association using Alternatives:

Use Verbatim to match a literal blank:

_ or Blank has special meaning in an association used as a pattern:

Use __ or BlankSequence to match more than one rule in an association:

Match an association containing a given rule and possibly more:

Match an association containing three elements:

Match nested associations:

Properties & Relations  (1)

Replace[expr,lhsrhs] returns a transformed result if and only if MatchQ[expr,lhs] yields True:

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

Text

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

CMS

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

APA

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

BibTeX

@misc{reference.wolfram_2024_matchq, author="Wolfram Research", title="{MatchQ}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/MatchQ.html}", note=[Accessed: 21-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_matchq, organization={Wolfram Research}, title={MatchQ}, year={2014}, url={https://reference.wolfram.com/language/ref/MatchQ.html}, note=[Accessed: 21-December-2024 ]}