I have a large expression, for example
Cos[x]Sin[y]Sqrt[1+z]/(1+x^2)-1/(1+y)
I wish to extract the argument inside Sqrt function, namely 1+z. I thought of using /.Sqrt[x_]->(h=x), but executing
Cos[x]Sin[y]Sqrt[1+z]/(1+x^2)-1/(1+y)/.Sqrt[x_]->(h=x);h
returns x but not 1+z, why? Is there a way to achieve my goal?
In my expressions, there will only be one Sqrt, but many other different heads as well. There is a similar question, but it is only applicable to very simple expression like Sqrt[1+z].
Rule(->) rather thanRuleDelayed(:>) – Bob Hanlon Mar 07 '20 at 20:23