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

164
Vistas
Replace a string value with another string value

I have a specific string /management/products.Here I'm trying to remove /management/ part from this string, So I'm expecting to return just products.

Here the code I tried,

let string = '/management/products'
string.replace(/^/management/i, "")

But this returns me a bunch of errors saying module bundle failed webpack

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

0

The issue is the escaping of the slashes in the regular expression. However, you do not need a regular expression at all!

With regular expression fixed:

let string = '/management/products';
string.replace(/\/management\//i, "");
// The slash is being used to end the regular expression,
// but by putting a backslash before it treats it like a regular character.

Without regular expressions at all:

let string = '/management/products';
string.replace('/management/', "");

If there are other strings other than /management/other arbitrary text here you would like this to work on, please edit your question.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use .split() if the part you want is always the second one.

let string = '/management/products'
string = string.split('/')[2]
console.log(string)

about 4 years ago · Juan Pablo Isaza Denunciar

0

Can you explain why did you give /^/management/i as first argument to the replace function instead of "/management/"?

Try this,

let string = '/management/products'
string.replace("/management/", "")

Thanks

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