I am trying to replace multiple \n
in a string but it never replace \n
. My same regex works properly in browser but why its not working inside node.js? Thanks.
My string:
var text = '\n\n\n\n\n\n\nYo! this is \n\n\n my string';
All of below regex works in browser, but not in 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);