Do replacement only on certain specific forms

If I want to replace, say, a with a1 + a2 in an expression, I can write

expr /. a -> a1 + a2

In some cases it might just be a matter of inverting things, such as the following substitutions

$$\qquad \phi=\varphi_{1}+\varphi_{2},\quad \delta=\varphi_{1}-\varphi_{2}$$

which can be inverted by solving for $$\varphi_1,\, \varphi_2$$ and then just using /.

But what about something more complex like this:

Sin[a + c] + Sin[c](Cos[b + c]a + Sin[Cos[a + c] + a*b]) + Log[a + b + c]

Let's say that I want to replace every instance of the expression a + b + c with S, and leave unchanged all the other expressions in which a, b or c appear but not in the form a + b + c.

How should I do this?

• See 3822 and links in Mr.Wizard's answer. Is that what you need? – Kuba Jan 29 at 14:55