luke (dot) wrote: > hi, > > i've found a great bit of code from > > http://dev.rubyonrails.org/ticket/1449 > > that takes some text and makes it wrap at 80 lines. the only issue is that > it takes multiple line breaks (like paragraphs), and makes them into single > line breaks. > > this is the code: > > text.gsub( /\n/, "\n\n" ).gsub( /(.{1,80})(\s+|$)/, "\\1\n") > > i've tinkered with it for a while, but i can't work out how to not have it > eat lines breaks so hungrily. > > thanks for any help > luke text.gsub( /(.{1,39}[^\s])([ \t]*\n[ \t]*|[ \t]+|$)/, "\\1\n")