1// regex global match for all variants of newlines
2/\r?\n|\r/g
3
4// example
5let foo = 'bar\nbar';
6foo = foo.replace(/\r?\n|\r/g, " "); /* replace all newlines with a space */
7console.log(foo); /* bar bar */
1var stringWithLineBreaks = `
2O boy
3I've got
4Breaks
5`;
6var stringWithoutLineBreaks = stringWithLineBreaks.replace(/(\r\n|\n|\r)/gm, "");//remove those line breaks