// regex global match for all variants of newlines / ? | /g // example let foo = 'bar bar'; foo = foo.replace(/ ? | /g, " "); /* replace all newlines with a space */ console.log(foo); /* bar bar */