On 02.02.2007 17:28, Phrogz wrote:
> On Feb 1, 11:25 pm, "Phrogz" <g... / refinery.com> wrote:
>> strings.each{ |str|
>>   puts str.gsub( /^(.{#{str.length/2},}?)\s(.+)/ ){ "#{$1}\n#{$2}" }
>>   puts
>>  }
> 
> Seeing Robert Klemme's regexp, it does make sense to be a hair
> greedier on the whitespace match, just in case the source string has
> more than one space between words at the boundary:
> 
> str.gsub( /^(.{#{str.length/2},}?)\s+(.+)/ ){ "#{$1}\n#{$2}" }

You're making length/2 the minimum for matching.  I believe that should 
rather be the max:

# untested
str.sub( /\A(.{1,#{str.length/2}})\s+(.+)/ ){ "#{$1}\n#{$2}" }

Also, #sub seems sufficient.

Kind regards

	robert