How can I match some parts of an expression?

Suppose I have an expression like Abs[x+I y]+Sin[Abs [c+ I (d+e)]],

and I want to replace all expressions in the form of Abs[a1 + I a2] to Sqrt[a1^2+a2^2].

How should I do that?

expr = Abs[x + I y] + Sin[Abs[c + I (d + e)]];

expr /. Abs[a_ + I*b_] -> Sqrt[a^2 + b^2]

(*  Sqrt[x^2 + y^2] + Sin[Sqrt[c^2 + (d + e)^2]]  *)


Have fun!

Use ComplexExpand

expr = Abs[x + I y] + Sin[Abs[c + I (d + e)]];

expr // ComplexExpand


Sqrt[x^2 + y^2] + Sin[Sqrt[c^2 + (d + e)^2]]

• It makes assumptions about symbols that are not necessarily in this form too. But as quick solution it is probably fine. – Kuba Apr 16 '15 at 7:35
• @Kuba - the second argument to ComplexExpand is used to designate any variables in the expression that are complex. – Bob Hanlon Apr 16 '15 at 12:38