我怎样才能删除每个只有一个双换行符的字符?
var string = "this is a ↵↵↵↵ test there will ↵↵ be more ↵↵↵↵ newline characters"
像这样
var string = "this is a ↵↵ test there will ↵ be more ↵↵ newline characters"
我已经试过了,但这会替换所有新行,我想保留单个行
string.replace(/[\n\n]/g, '')
最佳答案
string = string.replace(/\n{2}/g, '\n');
console.log(string);
那会做你解释的......但我相信你需要这个......
string = string.replace(/\n+/g, '\n');
console.log(string);
关于javascript - 只用一个替换双换行符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54770982/