I have written a regex pattern with positive look-behind in python
which matches a comma-separated list of mobile numbers. The pattern is:
^\+?[0-9]+((,?)(?(1)(\+?[0-9]+)))*$
It matches any mobile number regarding following constraints:
+
; any other +
characters are forbidden.00
.My pattern works fine in python
, but I want to convert it to javascript
version in order to use it in an angular
project.
I googled about javascript look-behind regex, but I couldn't figure out how to make use of indexed look-behind in javascript
; the ?(1)
part.
Is there any way to convert this python
regex to javascript
or any other equivalent regex to match my needs?
Given that your regex doesn’t seem to use lookbehinds or the no-clause of the conditional, I believe this should do it:
^\+?[0-9]+(,\+?[0-9]+)*$