Replace
expr rewritten by lhs -> rhs, but ONLY if the whole expression matches — unlike ReplaceAll, this never looks inside subexpressions.
✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram Language
Replace✓Replace(expr, lhs -> rhs)rhs (with wildcards substituted) if expr matches lhs at the top level, else expr unchangedReplace(expr, {rule1, rule2, …})like the 2-argument form, trying each rule in order and using the first that matchesReplace(expr, {{rules…}, {rules…}})each set of rules on its own, the answers as a listTyped signatures
| Type | Package | Applies |
|---|---|---|
(any, expression<Rule> | list<expression<Rule>> | list<list<expression<Rule>>>) -> any | combinatorics | always |
Details
- TOP LEVEL ONLY: this is the difference from compute-engine's own ReplaceAll (Wolfram's
/.), which recurses into every subexpression. Replace is Wolfram's own/.restricted to depth 0 — closer to Wolfram's ReplaceAll would actually beReplaceAllhere. - Built on BoxedExpression's own match/subs rather than compute-engine's replace method, which (probed) silently no-ops on a literal, non-wildcard match target reached through a boxed Rule.
Examples
About
| Examples | 9 |
|---|---|
| Checked against | Wolfram Language 7 agree |
| Crosswalk | Wolfram Language |
See also: MatchQ, ReplacePart