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

183
Vistas
Javascript - How to remove texts in between brackets

I'd like to know a simple way to change:

My name[1] is David Smith[ref.2] and my home is in Auburn[Geo-Ref3], AL.

into

My name is David Smith and my home is Auburn, AL.

If I do

string.replace(/\[.*\]/g, "")

then I get

My name, AL.

Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

.* will match greedily (as much as possible) by default. So the regex matched

My name[1] is David Smith[ref.2] and my home is in Auburn[Geo-Ref3], AL.
       ^----------------------------------------------------------^

You want to match reluctantly (as little as possible), which has syntax .*?. So use string.replace(/\[.*?\]/g, ""). This will match

My name[1] is David Smith[ref.2] and my home is in Auburn[Geo-Ref3], AL.
       ^-^               ^-----^                         ^--------^
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