1function nl2br(str){
2 return str.replace(/(?:\r\n|\r|\n)/g, '<br>');
3}
4var stringWithNewLines= `Well this is a
5a very broken
6sentance`;
7var stringWithBrs=nl2br(stringWithNewLines);
8// stringWithBrs= "Well this is a<br>a very <br>broken<br>sentance"
1var str = $("#mydiv").html();
2var regex = /<br\s*[\/]?>/gi;
3$("#mydiv").html(str.replace(regex, "\n"));