/\$(\w+) *(?=\[)/
Given the example $foo[9], your regex first
tries to match $foo, which fails because of
the negative lookahead assertion (i.e. it is followed by
[\w+]). Then it backtracks one character and
tries again; $fo fits what it's looking for
(\$(\w+), not followed by [\w+]),
so that's what it matches.
Your lookahead won't match the huge variety of Perl
expressions that could be used to index an array, but that's
okay, because all you need is to check for the opening
[ anyway.
It looks like you copied this code from somewhere else and
don't really understand it; I can't think of any other reason
you'd be using a negative lookahead there instead of a
positive one.
hdp. | [reply] [d/l] [select] |