Let say I have any expression
ex= f[h[r[x y]]] g[x z]
and I want to replace the x
with w
, but only for the x
within the head f
. Is there any simple way to do that?
Another, if I want to substitute an expression, say x
, but only if it it is inside a pattern, say complicateExpression x
, how can I do it? Of course, I can use the rule
complicateExpression x -> complicateExpression w
But this often means copy and paste complicateExpression
{f[args__]:>f@@({args}/.{x->w})}
$\endgroup$ – Hausdorff Jul 9 '20 at 9:48