From: phlip Date: 2008-07-13T05:50:42+09:00 Subject: Re: regular expressions help Axel wrote: > str = 'hi hello "hello world" hey yo' > str.gsub!( / \" [^\"]* \" /x ) {|e| e[1..-2].gsub(' ', "\007") } > result = str.scan( / [\w\007]+ /x ).map {|e| e.gsub("\007", " ") } > p result str = 'hi hello "hello world" hey yo' p str.scan(/(".*")|(\w+)/).flatten.compact => ["hi", "hello", "hello world", "hey", "yo"] Greedy matching to the rescue!