I have the following REGEX code, ie:
/^IT [0-9]{1,5}/(?<y1>19)?(?(y1)\d{2}|20\d{2})\((?<n1>M)?(?(n1)N|[H|B|C|D|E|G|K|M|U|N|L|S|T|V])\)$/
It is meant to check a group of words and ensure that it evaluates to:
IT 1/2014(G)
or any value up to 5 digits
IT 5000/2014(MN)
I keep getting the following error when running the above in firefox however:
Uncaught SyntaxError: invalid regexp group
Any help at all wouild be greatly appreciated.
The pattern contains an if clause which is not supported.
(?<y1>19)?(?(y1)\d{2}|20\d{2})
If group y1 exists, match 19 and 2 digits, else match 20 and 2 digits.
That can be written as (?:19|20)\d{2}
The same goes for
(?<n1>M)?(?(n1)N|[H|B|C|D|E|G|K|M|U|N|L|S|T|V])
If group n1 exists, match MN else match one of the listed in the character class.
That can be written as (?:MN|[HB-EGKMUNLSTV])
The whole pattern might look like:
^IT [0-9]{1,5}\/(?:19|20)\d{2}\((?:MN|[HB-EGKMUNLSTV])\)