str="Bla-bla,\n<bla-bla-bla, <pre>bla-bla,\n bla-bla-bla</pre>, bla-bla\n, mr. Freeman"; alert(str.replace(/\n(?![^<]*?\<\/)/g, "<br>"));