Pattern Language


The Mathematica pattern language is a rich system for matching and replacing parts of Mathematica expressions. A full description of the pattern language can be found in the main Mathematica documentation, http://reference.wolfram.com/mathematica/guide/RulesAndPatterns.html.

A quick summary of pattern primitives is shown in the following table.

Pattern Meaning
_ any expression
_h any expression with head h
__ any sequence of one or more expressions
__ any sequence of zero or more expressions
x_ named pattern
_:value optional pattern
Except[p] any expression except one that matches p