MatchQ

MatchQ[expr,form]

returns True if the pattern form matches expr, 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:

Introduced in 1988
 (1.0)
 |
Updated in 2014
 (10.0)