I am trying to replaces instances of \\r
or \\n
characters in my json object with
for display on a website.
I tried:<
Try this:
myString = myString.replace(/[\r\n]/g, "<br />");
Update:
As told by Pointy on the comment below, this would replace a squence of \r\n
with two <br />
, the correct regex should be:
myString = myString.replace(/\r?\n/g, "<br />");
This worked for me:
str = str.replace(/\\n|\\r\\n|\\r/g, '<br/>');
Using double slash
CSS:
white-space: pre-wrap;
Is a far more eficient method.
try replace(/\r\n|\n/, '<br />')