This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
 MATHEMATICA GUIDE Functions »| More About »| Tutorials »
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)
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
(Alternatives) any of several alternatives
(Repeated), (RepeatedNull) a pattern to be repeated
(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
pattern with a specified head h (e.g. Integer)
Condition (/;) condition on a pattern (e.g. )
PatternTest (?) pattern with a function test (e.g. NumberQ)
Pattern Defaults
(Optional) — pattern that defaults to e if omitted
_. (Optional) — pattern with predefined default
Default predefined default arguments for a function
Attributes Affecting Patterns

StringExpression symbolic string pattern

TUTORIALS