/ Published in: Ruby
Hat tip: Allan Odgaard
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def wrap_text(txt, col = 80) txt.gsub(/(.{1,#{col}})( +|$)\n?|(.{#{col}})/, "\\1\\3\n") end
URL: http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/