From: "David A. Black" Date: 2010-06-03T19:11:40+09:00 Subject: Re: Split text into equal characters but keeping whole words Hi -- On Thu, 3 Jun 2010, John Butler wrote: > Hi, > > I have text that is petty large. What i want to do is split it into an > array of no more than 250 characters per line but finishing on a full > word at the end of each line. So if the last word was "ruby" but 'b' > was the 250th character in the line then i want the line to cut off > before ruby and then start at ruby for the next line. What i have at > the minute is below which splits the text into an array of lines 250 > characters long, but as i say it slices through words at the end of the > 250 character limit. > > mytext.scan(/.{1,250}/m) > > Any ideas? The \b anchor (word boundary) might help you: mytext.scan(/.{1,250}\b/m) at least as a first approximation. You'll still have some edge cases and probably have to massage the output though. David -- David A. Black, Senior Developer, Cyrus Innovation Inc. THE Ruby training with Black/Brown/McAnally COMPLEAT Coming to Chicago area, June 18-19, 2010! RUBYIST http://www.compleatrubyist.com