html - Replace 1 newline with <br>, >= 2 with <br><br> -


i use following replace every linebreak <br>:

h(my_string).gsub(/(?:\n\r?|\r\n?)/, '<br>').html_safe 

i wonder if there solution if there's single linebreak, replace single <br>. , if there 2 or more linebreaks, replace 2 <br>, i.e. <br><br>?

you can iterate couple of times

h(my_string).gsub(/(\n\r?){2,}/, '<br><br>').gsub(/\n/, '<br>').html_safe 

Comments

Popular posts from this blog

ios - Change Storyboard View using Seague -

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -