我正在尝试替换字符串中的多个\n
,但它永远不会替换\n
。我的同一个正则表达式在浏览器中正常工作,但为什么它不在node.js内工作?感谢。
我的字符串:
var text = '\n\n\n\n\n\n\nYo! this is \n\n\n my string';
以下所有正则表达式都适用于浏览器,但不适用于nodejs:
var text = '\n\n\n\n\n\n\nYo! this is \n\n\n my string';
var test1 = text.replace(/[\r\n]{2,}/g, "");
console.log("test 1:", test1);
var test2 = text.trim();
console.log("test 2:", test2);
var test3 = text.replace(/\n+/g, "");
console.log("test 3:", test3);