I’m currently learning about regular expressions and I’m trying to create a regex to match any legal variable name in Perl.
This is what I wrote so far:
^\$[A-Za-z_][a-zA-Z0-9_]*
The only problem is the regex returns true for special signs, for example the string $a& will return true.
What I did wrong?
Thanks!
Rotem
You need a
$at the end, otherwise it’s just matches as far as it can and ignores the rest. So it should be: