DEV Community

Discussion on: 1 line of code: How to convert \newlines to <breaks />

Collapse
 
lexlohr profile image
Alex Lohr

If the regular expression is not dynamic, you can use a RegExp literal, ie. /\r?\n/g.

Collapse
 
martinkr profile image
Martin Krause

Hi Alex,

thank you for your contribution. Adjusted replace(new RegExp("\r?\n", "g"), "<br />") to replace(/\r?\n/g, "<br />")

Cheers!