You need to stop that by adding \w to the negative lookahead. s/(?<!\\)\$\w+(?![\[{\w])/whatever()/ge
I've replaced [a-zA-Z0-9_] with the more compact and equivalent \w, and tested for $bar{baz} as well.
This is still not perfect; it will munge $foo [5], which is valid (if rare) syntax. The easiest way to fix that is to use another regex, e.g. s/(\w) +([\[{])/$1$2/g
hdp.
In reply to Re: problem with substitution regex
by hdp
in thread problem with substitution regex
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |