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

154
Vistas
Regex replace strings matching pattern with multiple charercters

I have a string like this

const str = "Today is going to be @[City Temp](city-temp) in @[City Name](city-name)"

I want the output to be in handlebars syntax eg

const str = "Today is going to be {{city-temp}} in {{city-name}}"

I am having trouble trying to match this pattern.

I can see that if I do

str.replace(/[()]/g,"")

I get the string without the brackets.

But I can't work out how to search for the whole pattern something like the below where I find anything starting with @[ and ending with ), I don't want to just start with @ by itself as there may be times in the string I don't want to remove the @ where it is not followed by a [

/[\@\[A-Za-z0-9\](A-Za-z0-9-)

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

0

You can use

str = str.replace(/@\[[^\][]*]\(([^()]*)\)/g, "{{$1}}")

See the regex demo. Details:

  • @\[ - a @[ string
  • [^\][]* - zero or more chars other than [ and ]
  • ]\( - a ]( string
  • ([^()]*) - Group 1 ($1): any zero or more chars other than ( and )
  • \) - a ) char.

See the JavaScript demo:

const str = "Today is going to be @[City Temp](city-temp) in @[City Name](city-name)"
console.log(str.replace(/@\[[^\][]*]\(([^()]*)\)/g, "{{$1}}"))

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