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?
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).