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.
_ (
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
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
_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)
_:e (
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