# Separating variables in a set of equations

I have a very large set of equations eqs with variables denoted by capital letters like PVA, QA, etc. and small letters like ica[1,2], tr[2,3] etc. And I have variables denoted by Greek letters like alfa, beta etc. My goal is to create three lists of variables, one including only capital letters, the other only small letter etc. The order of the elements is not important but variables in the final lists should not be repeated. That is, PM may appear in several equations in the system but the list of variables with capital letter should include this variable only once, no repetition. Here is an example of a system of equations to use for this simple question. Thanks.

eqs={
WF WFDIST[2, 2] == (PVA QA $Alpha][2, 2])/QF[2, 2], EG == PQ qg + PQ qg + tr[1, 3] + tr[2, 3], QINT[1, 1] == ica[1, 1] QA, QINT[1, 2] == ica[1, 2] QA, QINT[2, 1] == ica[2, 1] QA, QINT[2, 2] == ica[2, 2] QA, QX == QA \[Theta][1, 1] + QA \[Theta][2, 1], QX == QA \[Theta][1, 2] + QA \[Theta][2, 2], QQ == aq (QD^-\[Rho]q (1 - \[Delta]q) + QM^-\[Rho]q \[Delta]q)^(-(1/\[Rho]q)) };  ## 2 Answers category[expr_] := Module[{fc = StringTake[ToString@expr, 1]}, Which[ MemberQ[CharacterRange["a", "z"], fc], 1, MemberQ[CharacterRange["A", "Z"], fc], 2, True, 3]]; categories[expr_] := Cases[expr, _[_?NumericQ ..], Infinity] // Union // (* SortBy[#, category] & // SplitBy[#, category] & *) GatherBy[#, category] & (* EDIT: more efficient *) eqs = { WF WFDIST[2, 2] == (PVA QA α[2, 2])/QF[2, 2], EG == PQ qg + PQ qg + tr[1, 3] + tr[2, 3], QINT[1, 1] == ica[1, 1] QA, QINT[1, 2] == ica[1, 2] QA, QINT[2, 1] == ica[2, 1] QA, QINT[2, 2] == ica[2, 2] QA, QX == QA θ[1, 1] + QA θ[2, 1], QX == QA θ[1, 2] + QA θ[2, 2], QQ == aq (QD^-ρq (1 - δq) + QM^-ρq δq)^(-(1/ρq))}; categories[eqs] (* {{aq, ica[1, 1], ica[1, 2], ica[2, 1], ica[2, 2], qg, qg, tr[1, 3], tr[2, 3]}, {EG, PQ, PQ, PVA, QA, QA, QD, QF[2, 2], QINT[1, 1], QINT[1, 2], QINT[2, 1], QINT[2, 2], QM, QQ, QX, QX, WF, WFDIST[2, 2]}, {α[2, 2], δq, θ[1, 1], θ[1, 2], θ[2, 1], θ[2, 2], ρq}} *)  Here is one option, if you don't mind converting back and forth from strings: st = ToString[InputForm[eqs]]; st2 = StringReplace[st, Whitespace -> ""]; (* Uppercase variables *) uppercase = Union[ToExpression[ StringCases[st2, RegularExpression["[A-Z]+\[[0-9]+,*[0-9]*$"]]]]

(* {EG, PQ, PQ, PVA, QA, QA, QD, QF[2, 2],
QINT[1, 1], QINT[1, 2], QINT[2, 1], QINT[2, 2], QM, QQ, QX,
QX, WF, WFDIST[2, 2]} *)

(* Lowercase variables *)
lowercase =
Union[ToExpression[
StringCases[st2, RegularExpression["[a-z]+$[0-9]+,*[0-9]*$"]]]]

(* {aq, ica[1, 1], ica[1, 2], ica[2, 1], ica[2, 2], q, qg,
qg, tr[1, 3], tr[2, 3]} *)

(* variables containing greek letters, possibly mixed with lowercase a-z *)
greek = Union[
ToExpression[
StringCases[st2,
RegularExpression[
"[a-z]*[$Alpha]-\[Omega]]+[a-z]*\[[0-9]+,*[0-9]*$"]]]]

(* {\[Alpha][2, 2], \[Delta]q, \[Theta][1, 1], \[Theta][1,
2], \[Theta][2, 1], \[Theta][2, 2], \[Rho]q} *)