SyntaxFix
Write A Post
Hire A Developer
Questions
You can use \n in a regex for newlines, and \r for carriage returns.
\n
\r
var str2 = str.replace(/\n|\r/g, "");
Different operating systems use different line endings, with varying mixtures of \n and \r. This regex will replace them all.