Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

245
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda