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

244
Visualizações
How would I select a value of a string that is in parentheses?

I want to select the contents of the second pair of parentheses in this string

"Hello my name is (john) (doe)."

How would I go about doing that? In addition, if there were an unknown number of pairs of parentheses, how would I be able to select the contents of the last one?

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

0

Here's a couple of possibilities. The first uses a regex to grab text between the last pair of parentheses (asserted using a lookahead that asserts there are no more opening parentheses after the last closing one), the second uses split, first on an opening parenthesis, grabbing the last value and then splitting that on a closing parenthesis and taking the first part of the result:

const str = "Hello my name is (john) (doe)."

result = str.match(/(?<=\()[^)]*(?=\)[^(]*$)/)[0]
console.log(result)

result = str.split('(').pop().split(')')[0]
console.log(result)

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