Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

279
Views
What would the correct syntax be for this REGEX expression?

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.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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])\)

Regex demo

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!