javascript remove line breaks from string
var stringWithLineBreaks = `
O boy
I've got
Breaks
`;
var stringWithoutLineBreaks = stringWithLineBreaks.replace(/(\r\n|\n|\r)/gm, "");//remove those line breaks// 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 */String.replace(/(\r\n|\n|\r)/gm," ")
Also in JavaScript:
- javascript remove all event listeners
- js paste event
- how to turn decimales into percents with javascript
- button not clicking for random jokes in javascript
- jquery add attribute without value
- postman test for true
- javascript press tab key
- Javascript append item to array
- javascript xml request
- javascript version of sleep
- pdf to image javascript
- js comparison operators
- join 2 array in javascript
- javscript remove a property
- install gatsbyjs using npx
- disabling submit button until all fields have values
- js settimeout
- input in js
- nan in js
- how to get time and date from iso string javascript
- chart.js cdn
- scrollview not working react-native
- add slashes to string
- change input placeholder text jquery