Removing backslashes from strings in javascript


I have a url in this format:


How can I remove the extra “\”s from the string? I have tried string.replace(“\”,””) but that does not seem to do anything. If you could give me a JavaScript regular expression that will catch this, that would also work too. I just need to be able capture this string when it is inside another string.



string.replace(/\\\//g, "/");

This will specifically match the “\/” pattern so that you don’t unintentionally remove any other backslashes that there may be in the URL (e.g. in the hash part).

Answered By – Ates Goral

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published