Posted By

breakerjump on 05/16/08


Tagged

text regular wrap Expression word


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


Text Wrapping with Regular Expressions


 / Published in: Ruby
 

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

Hat tip: Allan Odgaard

  1. def wrap_text(txt, col = 80)
  2. txt.gsub(/(.{1,#{col}})( +|$)\n?|(.{#{col}})/,
  3. "\\1\\3\n")
  4. end

Report this snippet  

You need to login to post a comment.