Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda