Clear["Global`*"]; expr = y[z] + x + Pi + m/Sin[a] + b[0]; DeleteDuplicates@Cases[expr, any_ /; Head[any] === Symbol && Not[MemberQ[Attributes[any], Constant]], Infinity]
Gives {x,n,a,x}. Note that the above does not detected indexed variables, such as \(b[0]\). The Attributes check is so not to include \(\pi \) since this is also a symbol. But we do not want to be there.