Patterns
Notes for Java programmers:
The Wolfram Language's pattern language lets you describe patterns for arbitrary symbolic structures, allowing powerful regex-like manipulation to be generalized to any expression and any form of data.
Notes for Python programmers:
The Wolfram Language's pattern language lets you describe patterns for arbitrary symbolic structures, allowing powerful regex-like manipulation to be generalized to any expression and any form of data.
Patterns stand for classes of expressions. The basic pattern construct _ (pronounced "blank") stands for any expression.
Find cases in a list matching the pattern f[_]:

Cases[{f[1], g[2], f[5], g[3]}, f[_]]

x_ (short for x:_) stands for a pattern whose value will be named x:


Replace[f[100], f[x_] -> x + 5]

/. means "replace everywhere":

{f[1], g[2], f[5], g[3]} /. f[x_] -> x + 5

Notes for Java programmers:
The sort of structural metaprogramming shown here is unique to the Wolfram Language's symbolic structure.
Notes for Python programmers:
The structural metaprogramming shown here, which treats code and data in the same way, is unique to the Wolfram Language's symbolic structure.
__ ("double blank") stands for any sequence of expressions:

Cases[{f[1, 2], f[1], g[3]}, f[__]]

a | b | c stands for a, b or c:

Cases[{f[1], g[2], f[2], f[5], g[3]}, f[1 | 5]]

Notes for Java programmers:
This usage of | resembles Java's regex notation, although in Java | can also indicate a bitwise OR.
Notes for Python programmers:
| is used in Wolfram Language patterns similarly to its use in Python's regular expressions. However, in the Wolfram Language, | works for any type of symbolic pattern matching, not just for strings.
It works in heads too:

Cases[{f[1], g[2], f[2], f[5], g[3]}, (f | g)[2]]

_h stands for any expression with head h:

Cases[{1, 2.5, 3.5, 4}, _Real]

QUICK REFERENCE: Operations Involving Patterns