且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JavaScript在字符串中将所有/替换为\?

更新时间:2023-02-23 12:58:37

是这样的:

str = str.replace(/\//g, "\\");

最后的/是正常的/pattern/格式,您需要为 \ 转义添加一个额外的内容,

the / on the end is the normal /pattern/ format, you need an extra for your \ escape, you can test it out here.