How can I read the line break from a value with JavaScript and replace all the line breaks with
elements?
Example:
A variable passe
This will turn all returns into HTML
str = str.replace(/(?:\r\n|\r|\n)/g, '
');
In case you wonder what ?: means.
It is called a non-capturing group. It means that group of regex within the parentheses won't be saved in memory to be referenced later.
You can check out these threads for more information:
https://stackoverflow.com/a/11530881/5042169
https://stackoverflow.com/a/36524555/5042169