我有这种格式的网址:
http:\ / \ / example.example.ru\ / u82651140\\ \\ / audio \ / song.mp3
如何从字符串中删除多余的\?我曾尝试string.replace(\,),但似乎没有做任何事情。如果你可以给我一个JavaScript正则表达式来解决这个问题,那也可以。我只需要能够捕获这个字符串时,它是在另一个字符串内。
解决方案尝试:
string.replace(/ \\\\ // g,/);这将特别匹配\ /模式,以便您不会无意中删除任何其他在URL中可能存在反斜杠(例如在散列部分)。
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 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.
解决方案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).
更多推荐
在javascript中删除字符串中的反斜杠
发布评论