Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!