This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
 BUILT-IN MATHEMATICA SYMBOL Tutorials »| See Also »| More About »

# Replace

 Replaceapplies a rule or list of rules in an attempt to transform the entire expression expr. Replaceapplies rules to parts of expr specified by levelspec.
• The rules must be of the form or .
• A list of rules can be given. The rules are tried in order. The result of the first one that applies is returned. If none of the rules apply, the original expr is returned.
• If the rules are given in nested lists, Replace is effectively mapped onto the inner lists. Thus Replace is equivalent to .
• Delayed rules defined with can contain conditions.
• Replace uses standard level specifications:
 n levels through n Infinity levels through Infinity {n} level n only {n1,n2} levels through
• The default value for levelspec in Replace is , corresponding to the whole expression.
• A positive level n consists of all parts of expr specified by n indices.
• A negative level -n consists of all parts of expr with depth n.
• Level consists of numbers, symbols, and other objects that do not have subparts.
• With the option setting Heads->True, Replace includes heads of expressions, and their parts.
• Replacements are performed to parts specified by levelspec even when those parts have Hold or related wrappers.
Replace by default applies rules only to complete expressions:
It does not map down to subparts:
A list of rules gives a list of results:
Replace by default applies rules only to complete expressions:
 Out[1]=
It does not map down to subparts:
 Out[2]=

A list of rules gives a list of results:
 Out[1]=
 Scope   (2)
Replace at level 1:
Replace also works with RuleDelayed:
New in 1 | Last modified in 4