Replace

WMA link


Replace[expr, x -> y]

yields the result of replacing expr with y if it matches the pattern x.

Replace[expr, x -> y, levelspec]

replaces only subexpressions at levels specified through levelspec.

Replace[expr, {x -> y, ...}]

performs replacement with multiple rules, yielding a single result expression.

Replace[expr, {{a -> b, ...}, {c -> d, ...}, ...}]

returns a list containing the result of performing each set of replacements.

By default, only the top level is searched for matches:

Replace stops after the first replacement:

Replace replaces the deepest levels first:

By default, heads are not replaced:

Heads can be replaced using the Heads option:

Note that heads are handled at the level of elements:

You can use Replace as an operator:

Dispatch
ReplaceAll