Regex question

Hi,

I’d like to replace all the ‘e’ which are not preceded and followed by an alphanumeric char.
Example:

hex -> no
2+e -> yes
e-1 -> yes

I made the following reggae but it seems not to work properly.

^a-zA-Z0-9_\$[^a-zA-Z0-9_]

Where is my error?

Thanks!

Your pattern requires such a character both before and after the “e”, which is not what you want. It’s also a good time to use a lookaround. Try this:

(?<![a-zA-Z0-9_\\$])e|e(?![a-zA-Z0-9_])

This will match an “e” if it meets one of those conditions using negative lookarounds.

thanks Kem. perfect as usual.