I have a text:
I need to replace one line break (\r\n) with “<br>” and when there are more than one line break replace it with one break.
For example:
LINE1
LINE2
LINE3
LINE4
LINE3
LINE4
Becomes:
LINE1<br>LINE2
LINE3<br>LINE4
LINE5<br>LINE6
Answer:
.replace(/([^\r\n])\r\n([^\r\n])/g, '$1<br>$2').replace(/[\r\n]+/g, "\r\n");
1 Answer