I am trying match variables with subscripts just returning true or false depending if pattern is matched. My try is to use Cases
. However the following does not return a match
Cases[Subscript[x, 2], Subscript[x, l_] /; l > 1]
Moreover, if this would work there must something nicer than
Length[ Cases[Subscript[x, 2], Subscript[x, l_] /; l > 1]]>=1
Cases[{Subscript[x, 2]}, Subscript[x, l_] /; l > 1]
,MatchQ[Subscript[x, 2], Subscript[x, l_] /; l > 1]
for just single test. $\endgroup$MatchQ
there is a bit wacky. Perhaps clarify more precisely what you want in the OP? It seems perhapsCases[Level[expression, Infinity], Subscript[x, l_] /; l > 1]
might be what you're after. $\endgroup$Not@FreeQ[(Subscript[x, 2])^2, Subscript[x, l_] /; l > 1]
? $\endgroup$