From: Siep Korteling Date: 2008-01-22T07:35:15+09:00 Subject: Re: Is there an easier way to get a match before a position in a string? William James wrote: ... > > > str = "\ > I don't necessarily need code examples -- but if anyone has > ideas for a best approach to specifying a line wrap width > (breaking between words for lines no longer than a specific > column width) for output from a Ruby script, I'd love to > hear about it." > > X = 40 > puts str.gsub(/\n/," ").scan(/\S.{0,#{X-2}}\S(?=\s|$)|\S+/) Kaspar Schiess wrote text-reform (gem install text-reform) require 'text/reform' r = Text::Reform.new while line=gets puts r.format('['*40, line) end Here he says it does hyphenate: http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/ -- Posted via http://www.ruby-forum.com/.