some code here
some code here
到
some code here
some code here
删除每个段落之间的空格的正则表达式是什么?我一直在寻找,但我找不到一个。一些结果将是:
some code heresome code here
但它不是我想要找到的那个
答案 0 :(得分:0)
将多个\n
替换为单个\n
:
var str = `some code here
some code here`;
console.log(str);
str = str.replace(/\n{2,}/g,'\n');
console.log(str);

答案 1 :(得分:0)
replace
包含一个换行符的1个或多个\n
(换行符)字符:
const input = `some code here
some code here
some code here
some code here
some code here`;
const output = input.replace(/\n+/g, '\n');
console.log(output);