0

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:

  1. Each phone number can start with +; any other + characters are forbidden.
  2. Each phone number can start with 00.
  3. Spaces are not acceptable; not middle spaces nor peripherals.

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?

Zeinab Abbasimazar
  • 9,835
  • 23
  • 82
  • 131
  • 1
    There is no lookbebhind in the pattern, there is a conditional construct here, and I doubt it works as expected since your group 1 is `((,?)(?(1)(\+?[0-9]+)))`. I think what you were after is a plain [`^\+?[0-9]+(?:,\+?[0-9]+)*$`](https://regex101.com/r/NzStiy/1) pattern. – Wiktor Stribiżew Jul 11 '18 at 11:40
  • I’m not sure I understand the use of the conditional here. It looks to me like you could add the yes clause directly after the comma. – Aankhen Jul 11 '18 at 11:40

1 Answers1

0

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]+)*$
Aankhen
  • 2,198
  • 11
  • 19