I have a working version of PCRE regular expression that checks is a given string matches French licence plates. It goes like this (live demo):
/^(?(?!ss|ww)[a-hj-np-tv-z]{2})(?:\s|-)?[0-9]{3}(?:\s|-)?(?(?!ss)[a-hj-np-tv-z]{2})$/i
Now I would like to transform it to JavaScript regex syntax. I understand that conditional regex syntax used here is not supported by JavaScript regex engine, so I should rewrite it.
I've started with a first group which:
- Has to have two letters
- They can't be SS nor WW
- They can't use I, O, U
This is what I've come up with (live demo):
/^(?!(?=(?:ss|ww))|(?![a-hj-np-tv-z]{2}))/i
And it works. Now I would like to add second part:
- The first group can be (but doesn't have to be) followed by a white space character or a hyphen.
- After that there is a group of exactly 3 digits.
So I've tried to add (?:\s|-)?[0-9]{3}
and it fails. I guess it may have something to do with the fact that the very first group is not consumed, but I don't understand why. Optionally if anyone would also be able to help me with info on how to create a capturing group of the group of first two letters (I don't need it now, but hat would help me understand the process).