Removing backslashes from strings in javascript

后端 未结 3 641
粉色の甜心
粉色の甜心 2020-12-03 03:41

I have a url in this format:

http:\\/\\/example.example.ru\\/u82651140\\/audio\\/song.mp3

How can I remove the extra \"\\\"s from the string? I

相关标签:
3条回答
  • 2020-12-03 04:13

    Try

    str = str.replace(/\\/g, '');
    
    0 讨论(0)
  • 2020-12-03 04:14

    Try:

    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).

    0 讨论(0)
  • 2020-12-03 04:16

    from: http://knowledge-serve.blogspot.com/2012/08/javascript-remove-all-backslash-from.html

    function replaceAllBackSlash(targetStr){
        var index=targetStr.indexOf("\\");
        while(index >= 0){
            targetStr=targetStr.replace("\\","");
            index=targetStr.indexOf("\\");
        }
        return targetStr;
    }
    
    0 讨论(0)
提交回复
热议问题