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

109
Vistas
Javascript Regex Replace Without Resolving Backreference

I'm trying to replace a password token [**PASSWORD**] in a string with the password and am having trouble with passwords that contain the string $&.

For example:

var re = new RegExp('(?:\\[\\*\\*PASSWORD\\*\\*\\])', 'g');
'Your temporary password is: [**PASSWORD**]'.replace(re, 'B9z3$&dd');

I want the output to be Your temporary password is: B9z3$&dd, but instead the $& is resolving the backreference to [**PASSWORD**] which makes the output Your temporary password is: B9z3[**PASSWORD**]dd

How can I prevent Javascript from resolving the backreference and simply insert the text as-is?

Thank you!

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

0

You need to escape the $ in your replacement string doubling it: B9z3$$&dd.

Here's a demo:

result = 'Your temporary password is: [**PASSWORD**]'.replace(/\[\*\*PASSWORD\*\*\]/mg, "B9z3$$&dd");

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