# Extract terms containing a specific symbol from an expression

I would like to be able to extract terms that contain either a symbol or a small expression from a larger one.

Example (with a somewhat complicated function to give the idea of what I am after):

-R (δt + 2 θ2t Sin[θ1]) +
2 Cos[ϕ/
2] (Sin[δ/
2] (vz Sin[θ2] +
Cos[θ2] (vy Cos[θ3] +
h θ3t Sin[θ1] - vx Sin[θ3])) +
Cos[δ/
2] (h (θ1t + θ3t Sin[θ2]) -
Sin[θ1] (vz Cos[θ2] -
vy Cos[θ3] Sin[θ2] +
vx Sin[θ2] Sin[θ3]))) -
2 l θ2t Cos[δ/2] Sin[θ1] Sin[ϕ/2] -
2 Cos[θ1] (-Cos[ϕ/2] (-h θ2t Sin[δ/2] +
Cos[δ/
2] (vx Cos[θ3] +
vy Sin[θ3])) + θ3t Cos[θ2] (R +
l Cos[δ/2] Sin[ϕ/2]))


I would like Mma to return all the terms that multiply vx:

2 Cos[ϕ/
2] (Sin[δ/
2]Sin[θ3]))-2 Cos[θ1] -Cos[ϕ/2]
Cos[δ/2] Cos[θ3]


Coefficient[expr, vx] // Simplify where expr is your expression.

Update

Coefficient[expr, Sin[\[Theta]2]] // Simplify • Would this work if instead of vx I had an expression like $\sin\theta_2$? – usumdelphini Jan 29 at 14:16
• @usumdelphini Yes, I think so. Please see the updated part. – Αλέξανδρος Ζεγγ Jan 29 at 14:30