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

140
Visualizações
Regex contains runaway part

I'm building a Regex to parse some "filter strings". String which contains conditions which have to match, combined by "and" or "or" operators. For this I needed a regex which searches for matching brackets.¨

A filter string can look like this: (param2="def" or param2="ghj") and param1="abc"

It works as expected, but if I enter a typo, like a newer closing bracket, I receive an error for "Runaway Regular Expression"

The part of the regex which is looking for matching brackets: /\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/

If I test this regex with following string (description=r\"Sending \[A-Z0-9]{8}\"), and if I add a opening bracket "(" anywhere inside, it's throwing the error.

Especially in JavaScript I'm not sure if there is a way to catch this error.

Regex Demo: https://regex101.com/r/eE6mX3/1

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to re-write the pattern so that it matched:

  • a ( char
    • any chars other than ( and )
    • zero or more occurrences of
      • a ( char
      • any chars other than ( and )
      • a ) char
      • any chars other than ( and )

This way, the pattern will be as efficient as possible:

\([^()]*(?:\([^()]*\)[^()]*)*\)

See the regex demo.

about 4 years ago · Juan Pablo Isaza 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