in reply to problem with substitution regex
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: problem with substitution regex
by MeowChow (Vicar) on Apr 27, 2001 at 03:41 UTC | |
by hdp (Beadle) on Apr 27, 2001 at 03:42 UTC |