0

For some weird reason, I can't seem to figure out how to solve my current issue.

I have a string that contains this string /partners: and I wish to remove all occurrences of /partners: from the string

I have tried the below code

retrievedData = retrievedData
            .replace("/\/partners:", "")

But for some weird reason it is not working.

Any help would be greatly appreciated.

ololo
  • 1,326
  • 2
  • 14
  • 47
  • Use either `replaceAll` or a regex literal instead – CertainPerformance Apr 29 '21 at 16:48
  • that's not regex – boxdox Apr 29 '21 at 16:49
  • 1
    I think you want `replace(/\/partners:/g, "")` – Charlie Bamford Apr 29 '21 at 16:50
  • When you pass a string to `replace`, it looks for **exactly** that string. Your string has two `/` in it at the beginning (one of them pointlessly escaped), so naturally it doesn't match a string with just one `/` at the beginning. To match `/partners:`, use `.replace("/partners:", "")`. If you need to use a regular expression, though, then in the regular expression literal you'd have to escape the `/`: `.replace(/\/partners:/, "")`. But there's no indication you need a regular expression here. – T.J. Crowder Apr 29 '21 at 16:50

0 Answers0