[JavaScript] Regular Expression and Snippet to Replace Line Break Characters \r\n \r \n with Spaces
I’ll introduce a regular expression and snippet to replace line break characters with spaces in JavaScript.
var text = 'spam\\r\\nspam\\rspam\\nspam';
console.log(text);
// spam
// spam
// spam
var replacedText = text.replace(/\\r\\n|\\r|\\n/g, ' ');
console.log(replacedText);
// spam spam spam spam
It replaces any pattern of \r\n, \r, or \n with a space.
That’s all from the Gemba.