# How to select terms which contain certain letters?

I would like to select the term Subscript[Cos\[CapitalDelta], Subscript[p, B]] of expression

     Times[Complex[0,32],
Dot[Cross[OverVector[n],Subscript[OverVector[Δ],1]],
Subscript[OverVector[Δ],A]],Dot[Subscript[OverVector[Δ],1],Derivative[1]
[Subscript[OverVector[Δ],A]]],
Subscript[CosΔ,
Subscript[p,B]],
Subscript[SinΔ,Subscript[p,A]],Derivative[1][Subscript[CosΔ,Subscript[p,B]]],Derivative[1]
[Subscript[SinΔ,Subscript[p,A]]]]


I can use Take[exp,{-3}] but it is not general. The selection rule should indeed be the terms that start with C. For example, in the above expression, I want terms Subscript[CosΔ, Subscript[p, B]] and Derivative[1][Subscript[CosΔ, Subscript[p, B]]].

For other times I may have expression like

    Times[Complex[0,32],m,Ε2,
Dot[Cross[OverVector[n],Subscript[OverHat[OverVector[p]],A]],
Subscript[OverVector[Δ],A]],Subscript[C,Subscript[p,B]],
Subscript[S,Subscript[p,A]],
Subscript[SinΔ,
Subscript[p,A]],Derivative[1][
Subscript[CosΔ,Subscript[p,B]]]]


For this expression, I really need the term

 Subscript[C, Subscript[p, B]]


Can anyone help me with this?

• In your expressions it is not clear, how their terms are connected to one another. Now they are simply written as several different input lines within the same cell. Do they form a list? Or, may be, they should be connected by the sign plus? Or what? Further, what do you mean by such a notation as Subscript[Cos\[CapitalDelta], Subscript[p, B]]? Do you mean, may be, Cos[Subscript[\[CapitalDelta], Subscript[p,B]]]? – Alexei Boulbitch Aug 27 '18 at 9:38
• @ Alexei Boulbitch sorry, I have changed the messy code. Now, it is more clear. – ZHANG Juenjie Aug 27 '18 at 12:15
• It still seems to contain a syntax error: Subscript[Cos\[CapitalDelta], Subscript[p, B]] does not exist within the Mma syntax, unless you mean that it is such a variable with so a strange name. Further, now your expression represents a single term: a product of several factors. In this case I do not understand the sense of your question. – Alexei Boulbitch Aug 27 '18 at 12:55

In the first case, this may work out:

FullForm /@ Cases[
exp,
x : Subscript[a_, b_] /; StringTake[ToString[a], {1, 1}] == "C",
All
]


{Subscript[CosΔ, Subscript[p, B]], Subscript[CosΔ, Subscript[p, B]]}

It does miss the derivative around the second occurrence, though. I don't know whether this iss desired or not.

• @ Henrik Schumacher How to take into account the Derivative? – ZHANG Juenjie Aug 27 '18 at 12:57
• Cases[exp, x : (Derivative[1][Subscript[a_, b_]]) | Subscript[a_, b_] /; StringTake[ToString[a], {1, 1}] == "C", All] – ZHANG Juenjie Aug 27 '18 at 12:59