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

230
Visualizações
How do you determine, using RegExp, whether or not a substring is between parentheses?

Might be a duplicate; I thought this question had to have been already asked, but I searched and couldn’t find one.

How do you determine, using RegExp, whether or not a substring is between parentheses?

Say I want to check if the text “fox” is surrounded by parentheses in the following sentence:

The (quick) brown fox jumps (over the lazy) dog.

I tried this RegEx, but it tests true when “fox” is actually not parenthesized but does have parentheses to its left and right:

\(.*?fox.*?\)

I tried it with negative lookbehind and negative lookahead, and it doesn’t work either:

\(.*?(?<!\)).*?fox.*?(?!\().*?\)
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

This will match any term in parenthesis:

\(.*?\)

The (quick) brown fox jumps (over) the lazy dog.

This question mark will ensure that the regex is 'lazy' and will only match the first instance of a closing parenthesis.

Removing the question mark like this: \(.*\) will give you the following match, which is probably not what you want:

The (quick) brown fox jumps (over) the lazy dog.

If you literally only want to match "(fox)", then the correct regex is:

\(fox\)

You can use an online regex tester or text editor to answer these kind of questions.

about 4 years ago · Juan Pablo Isaza Relatório

0

Here's a way to guaranteed that the word exists in inner parentheses only without existing in something nested:

https://regex101.com/r/UlQpM6/1

\([^()]*fox[^()]*\)

\( - Open

[^()]* - 0 or more of any character that isn't parentheses

fox - fox

[^()]* - repeat pattern

\) - Close

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