Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我尝试将“\”字符替换为空“”,但我做不到。如何解决?
这是我的代码
abc = abc.replace('\','');
要替换字符串中的所有匹配项,您需要使用带有g标志的正则表达式,
g
abc = abc.replace(/\\/g, '');
我认为您需要转义反斜杠:
abc = abc.replace('\\', '');
如果要替换所有匹配项,可以尝试:
var pattern = '\\\\'; var re = new RegExp(pattern, 'g'); abc = abc.replace(re, '');