I have the following regular expression:
[^0-9+-]|(?<=.)[+-]
This regex matches either a non-digit and not +
and -
or +
/-
preceded by something. However, positive lookbehind isn't supported in JavaScript regex. How can I make it work?
The (?<=.)
lookbehind just makes sure the subsequent pattern is not located at the start of the string. In JS, it is easy to do with (?!^)
lookahead:
[^0-9+-]|(?!^)[+-]
^^^^^
See the regex demo (cf. the original regex demo).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With