使用 Javascript/jQuery 删除字符串中的反斜杠
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11712227/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
removing backslash in a string with Javascript/jQuery
提问by xiaolong
When I query twitter feeds, the returned profile url contains backslashs and looks like:
当我查询 Twitter 提要时,返回的配置文件 URL 包含反斜杠,如下所示:
"http:\/\/a0.twimg.com\/profile_images\/2419298032\/image_normal.jpg"
how to remove the backslashes to make it look like:
如何删除反斜杠以使其看起来像:
"http://a0.twimg.com/profile_images/2419298032/image_normal.jpg"
Thanks a lot!
非常感谢!
P.S. seems
PS好像
x=x.replace(/\/gi, "");
doesn't work...
不起作用...
回答by Stefan Profanter
x = x.replace(/\\/g, '');
x = x.replace(/\\/g, '');
You have to use two backslashes to get the \ character. A single backslash is used for control characters such as \r \n etc. Using the double backslash escapes this and gives you what you want.
您必须使用两个反斜杠来获取 \ 字符。单个反斜杠用于控制字符,例如 \r\n 等。使用双反斜杠可以转义这一点,并为您提供所需的内容。
See also: how can remove backslash in value by jQuery?
另请参阅:如何通过 jQuery 删除反斜杠值?