This is documentation for Mathematica 7, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
Patterns
One of the unique strengths of Mathematica's core language is its powerful and succinct—yet highly readable—symbolic pattern language. Convenient both for immediate use in individual functions, and for systematic large-scale programming, Mathematica's pattern language generalizes concepts like regular expressions to describe general patterns for arbitrary symbolic structures.
Basic Pattern Objects
_ (Blank)— any expression (a "blank" to be filled in)
x_ any expression, to be referred to as x
__ (BlankSequence)— any sequence of one or more expressions
___ (BlankNullSequence)— any sequence of zero or more expressions
Composite Patterns
p|p|p (Alternatives) any of several alternatives
p.. (Repeated), p... (RepeatedNull) a pattern to be repeated
x:p (Pattern) — an arbitrary pattern, to be referred to as x
Except anything except a specified pattern
Longest, Shortest longest, shortest possible matches
Restrictions on Patterns
_h pattern with a specified head h (e.g. _Integer)
Condition (/;) condition on a pattern (e.g. x_/;x>7)
PatternTest (?) pattern with a function test (e.g. _?NumberQ)
Pattern Defaults
_:e (Optional) — pattern that defaults to e if omitted
_. (Optional) — pattern with predefined default
Default predefined default arguments for a function
Attributes Affecting Patterns
Orderless  ▪ Flat  ▪ OneIdentity
    
StringExpression symbolic string pattern
    
MatchQ  ▪ Cases  ▪ Position  ▪ Count  ▪ ...
TUTORIALS
MORE ABOUT