# Replace pattern within a specific pattern only

I have expressions like

tc*Cos[2*w*(t0+tc)]


and I want to replace tc by something else, but only if it occurs inside Cos, i.e. the outer tc should remain as is. Is there any way of specifying the context in which Replace should act? Maybe some clever pattern tricks?

Note that the actual expressions I'm working on are more complicated and consist of more (similar) terms, so just skipping over the first occurrence isn't going to cut it.

Thanks!

• ReplaceAll[c_Cos?(Not@*FreeQ[tc]):>ReplaceAll[c, tc->new]] should do it. It's not a nice pattern to work with. Will be slow. But if the tc can appear in an arbitrary expression within Cos then there's not too much else I know to do. – b3m2a1 Dec 6 '17 at 16:43
• The solution by QuantumDot below works like a charm! Also, in the mean time I've found a related, more general question (with answers) here – Jesse Slim Dec 12 '17 at 13:09

expr = tc*Cos[2*w*(t0+tc)]

expr /. (Cos[arg_] :> Cos[arg /. tc -> new])

tc Cos[2 (new + t0) w]