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

96
Vistas
Replace any of several characters with underscore

I have a simple task but I'm not sure of the syntax.

I have a string and want to replace any occurrences of '[', ']', or '.' with an underscore ('_').

I know that string.replace() supports regular expressions, which also give special treatment to [ and ].

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

0

Use replaceAll for that

** Note, replace will also work since this a global search.

const src = '/[[\].]/g';
const target = '_';

const formated = string.replaceAll(src, target);

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll

about 4 years ago · Juan Pablo Isaza Denunciar

0

Escape the characters with special treatment with backslash.

string = string.replace(/[[\].]/g, '_');

Note that [ and . don't receive special treatment inside [].

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