From: "David A. Black" Date: 2008-07-13T06:04:52+09:00 Subject: Re: regular expressions help Hi -- On Sun, 13 Jul 2008, phlip wrote: >> str = 'hi hello "hello world" hey yo' >> p str.scan(/(".*")|(\w+)/).flatten.compact >> >> => ["hi", "hello", "hello world", "hey", "yo"] >> >> Greedy matching to the rescue! > > Also, non-capturing groups help us remove the .flatten.compact nonsense: > > p str.scan(/(?:".*")|(?:\w+)/) > > => ["hi", "hello", "\"hello world\"", "hey", "yo"] > > I'm not sure why one version capture the "" marks and the other did not... They both did :-) (See my previous post.) David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails July 21-24 Edison, NJ Advancing With Rails August 18-21 Edison, NJ See http://www.rubypal.com for details and updates!