我正在使用replace
函数删除不需要的字符,例如:
var test = "one line \n another line";
test = test.replace(/[^a-z0-9äöåÄÖÅ"\${}()%&#!¡¿?"'><.,;:=\/*+-_ \^]/g, '')
结果:
"one line another line";
如果您注意到了两个空格,它只是删除了 \ n
我注意到它删除了 \ n ,但是如果在replace regex中未指定怎么办?
答案 0 :(得分:2)
var test = "one line \n another line";
test = test.replace(/[^a-z0-9äöåÄÖÅ"\${}()%&#!¡¿?"'><.,;:=\/*+-_ \^\r\n]/g, '')
// ________________________________________________________________^^^^
console.log(test)