Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

280
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda