Text Wrapping with Regular Expressions

def wrap_text(txt, col = 80)
txt.gsub(/(.{1,#{col}})( +|$)
?|(.{#{col}})/,
"13
")
end

source

Leave a Reply