Wolfram Language & System 11.0 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)


One of the unique strengths of the Wolfram Language is its powerful and succinctyet highly readablesymbolic pattern language. Convenient both for immediate use in individual functions, and for systematic large-scale programming, the Wolfram Language'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

OptionsPattern  ▪  PatternSequence  ▪  Verbatim  ▪  HoldPattern

OrderlessPatternSequence elements in any order

KeyValuePattern an association or list of rules containing specified elements

Restrictions on Patterns

_h 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

_: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

String Patterns »

StringExpression symbolic string pattern

Pattern Matching Functions »

MatchQ  ▪  Cases  ▪  Position  ▪  Count  ▪  ...