From: James Edward Gray II Date: 2006-01-04T07:33:56+09:00 Subject: Re: silly regex question On Jan 3, 2006, at 4:22 PM, Joe Van Dyk wrote: > Can someone help me make this code not suck? I guess it depends on what you mean by that... > require 'test/unit' > > # EWWWWWWW > def process_string str > result = Hash.new > str.to_a.each do |line| > line.scan(/important ([a-zA-Z0-9]+): /) do |key| > result[key.first] = line > end > end > result > end def process_string str Hash[*str.scan(/^\s*(important ([a-zA-Z0-9]+): .+) $/).flatten.reverse] end James Edward Gray II