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

322
Vistas
Adding a multiple space character's in nodejs using replace method

I have the following variable.

var s = 'Hi Al !'

Which i would like to convert to

'Hi    Al !'

I.E. basically add 4 space characters and hence taught i could do the following:-

var new_var = s.replace('Hi', 'Hi\s\s\s\s');

But the above only gives me the output Hissss Al !, which is not what i want. How do i add 4 space characters to my string ?

I have also tried var new_var = s.replace('Hi', 'Hi\t');

But the output has about 6-7 spaces.

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

0

Just use the space character:

var s = 'Hi Al !'
var new_var = s.replace('Hi', 'Hi    ');
console.log(new_var)

about 4 years ago · Juan Pablo Isaza Denunciar

0

Using \s matches a whitespace char using a regular expression. If you use that in the replacement, it will just be s

If there is a variable number of spaces after Hi, and you want to change that to always have 4 spaces, you can match 1 or more whitespace chars and use 4 spaces in the replacement.

var s = 'Hi              Al !';
var new_var = s.replace(/Hi\s+/, 'Hi    ');
console.log(new_var)

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