From: Bill Kelly Date: 2008-07-13T06:17:38+09:00 Subject: Re: regular expressions help From: "phlip" > > p str.scan(/(?:".*")|(?:\w+)/) > > => ["hi", "hello", "\"hello world\"", "hey", "yo"] Probably want: str.scan(/(?:"[^"]*")|(?:\w+)/) ...else the greediness will extend over multiple quoted strings... 'hi hello "hello world" hey yo "marmoset knocked you out" foo bar' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ vs. 'hi hello "hello world" hey yo "marmoset knocked you out" foo bar' ^^^^^^^^^^^^^ > I'm not sure why one version capture the "" marks and the > other did not... Strange... They both did, on my system...(?) BTW, in ruby 1.9, we have lookbehind, so we can avoid picking up the quotes, with: str.scan(/(?:(?<=")[^"]*(?="))|(?:\w+)/) Regards, Bill