javascript replace newline with br

function nl2br(str){
return str.replace(/(?:\r\n|\r|\n)/g, '<br>');
}
var stringWithNewLines= `Well this is a
a very broken
sentance`;
var stringWithBrs=nl2br(stringWithNewLines);
// stringWithBrs= "Well this is a<br>a very <br>broken<br>sentance"

4.25
4
Tammy Lin 110 points

                                    var str = $(&quot;#mydiv&quot;).html();
var regex = /&lt;br\s*[\/]?&gt;/gi;
$(&quot;#mydiv&quot;).html(str.replace(regex, &quot;\n&quot;));

4.25 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
javascript replace string with new line replace line break with html line break js javascript replace br to newline js replace br with new line javascript replace br real js replace , with line break javascript replace , with line break replace line break with n in javascript replace \n with actual new lines javscript javascript replace br tag with new line javascript replace \n with br how to replace new line in js javascript replace new line character new line using in the replace method in javascript string javascript replace \n with real new line replace something with new line in js javascript replace with new line javascript replace string with newline how to replace new line character in javascript replace /n with line breaks js js replace &lt;br&gt; to \n javascript replace line breaks with n javascript replace new line with \n js n replace br js br replace \n js text replace &lt;br&gt; replace java new line with br javascript replace \n from string js Replace new line character with &quot;\n&quot; in javascript Replace new line character in javascript javascript replace new line in string javascript how to replace br tag with \n javascript string replace newline js.replace new lines with &quot;&quot; .replace n with break javascript javascript replace line break with br javascript replace r n with br how to replace \n with \\n in javascript javascript string replace new line character replace string with new line in javascript replace break line javascript js replace newline with p element replace endline in string js replace &lt;br&gt; with \n javascript replace \n javascript convert text with to html javascript javascript string replace with newlines javascript replace line return with \n js replace new line br replace new line javascript replace character in a string with newline javascript replace character with newline javascript replace with newline javascript js string replace newline replace newline javascript how to replace newline javascript replace all linebreaks with &lt;br&gt; js javascript replace newline with paragraph replace the enter symbol with new line javascript javascript replace \n javascript replace \r\n\t javascript replace \r\n replace \n\t from string in javascript how to replace \n from string js replace \r\n/ with br javascript js replace new line with br replace \n with br js replace n in js js replace \n with line breaks js replace \n with br tag replace break lines javascript js replace line break wit hnothing js replace line breaks javascript replace br tag with newline replace line break js string replace line break javascript replace br with n in javascript replace r n with br javascript replace br javascript replace new lines javascript string replace newline javascript javscript replace by newline javascript replace newline with space javascript .replace \n javascript replace line break how to replace br with newline in javascript javascript replace n to br replace /n with newline js str.replace newline javascript javascript replace line breaks replace javascript \n js replace newline character javascript replace with &lt;br&gt; js insert line break in string replace br with newline javascript replace \n in js js replace &lt;br/&gt; nodejs replace \n with newline javascript replace with string with newline how to replace new line js replace new line in string javascript replace n in javascript js replace n with br js replace break line replace n with br javascript replace line breaks in string javascript javascript replace br in string replace n to br javascript replace new lines with \n in js replace line breaks with \n js replace \n with new string javascript javascript string replace new line with br javascript replace new lines replace with line break in javascript javascript replace &lt;br/&gt; change br with \n js javascript carriage return and new line character replace replace n with newline javascript replace line break with br javascript replace br to newline in javascript js replace newline replace newline js replace newlines js remove line breaks javascript readline javascript replace line breaks with space javascript replace all new line javascript replace character with line break js replace \n clear line space nodejs how to remove newlines in a string javascript js replace newline with space javascript replace line breaks with br javascript remove all \n replace newline with space javascript js replace line breaks with br jquery remove newline from string jquery remove line breaks from html js code delete line replace new line with br js js replace new line replace space with new line js javascript replace new line with br replace space with line break javascript javascript replace space with line break replace \n js javascript replace newline replace new line textarea in javascript convert text with \r\n to html javascript javascript replace newline with br .replace(/(\r\n|\n|\r)/gm, &quot;,&quot;); string replace new line javascript php remove line break php replace spaces how to add vertical lines in html unix + remove blank lines from a file convert \r\n\r\n to a new line js
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source