javascript remove line breaks from string
snippet in javascript

javascript remove line breaks from string

user8497

var stringWithLineBreaks = `
O boy 
I've got 
Breaks
`;
var stringWithoutLineBreaks = stringWithLineBreaks.replace(/(\r\n|\n|\r)/gm, "");//remove those line breaks

javascript remove all newlines

user3923

// regex global match for all variants of newlines
/\r?\n|\r/g

// example
let foo = 'bar\nbar';
foo = foo.replace(/\r?\n|\r/g, " "); /* replace all newlines with a space */
console.log(foo); /* bar bar */

Remove line breaks with JavaScript

user9195

String.replace(/(\r\n|\n|\r)/gm," ")