Text Wrapping with Regular Expressions

/ Published in: Ruby
Save to your folder(s)

Hat tip: Allan Odgaard

Copy this code and paste it in your HTML
  1. def wrap_text(txt, col = 80)
  2. txt.gsub(/(.{1,#{col}})( +|$)\n?|(.{#{col}})/,
  3. "\\1\\3\n")
  4. end

URL: http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.