Seemingly a relatively simple problem, I can't seem to find a solution...
I want to build a pattern that will match any symbol whose name starts with V, and is elevated at any power. Something on the line of:
MatchQ[#1, (V1 | V2 | V3)^_.] & /@ {V1, V1^2, V2}
That returns true for each of the entries. I haven't found a way to put constrains on the symbol name, if not by using SymbolName[] and working with string patterns:
MatchQ[#1, (_)?(StringMatchQ[SymbolName[#1], "V" ~~ __] &)^_.] & /@ {V1, V1^2, V2}
However, it doesn't look exactly beautiful... (only to me?) :-) Is there a more compact and elegant way of putting constraints on a symbol name? I'm feeling like I'm totally missing a very obvious function that would do that...
_(sort of * for symbol names), then there musts be a syntax to compare only part of the name (eventually completed by wildcards). Now I realize that 'MatchQ' compares the content of the symbols, hence the need to useSymbolNameif you want to put constraints on the name... probably this was very clear to everyone except me! :-) – Giacomo Ciani Feb 19 '15 at 03:34