On Mon, 2006-01-09 at 18:13 +0900, William James wrote:
> Richard Livsey wrote:
> > I want to split a string into words, but group quoted words together
> > such that...
> >
> > some words "some quoted text" some more words
> >
> > would get split up into:
> >
> > ["some", "words", "some quoted text", "some", "more", "words"]
> 
> s = 'some words "some quoted text" some more words'
> p s.split( / *"(.*?)" *| / )
> 

Which along with the CSV solution can't handle complex cases:

 s='one two"  "\'with quotes\' "three "'

 s.split( / *"(.*?)" *| / )
 => ["one", "two", "  ", "'with", "quotes'", "three "]

 require 'csv'
 CSV::parse_line(s)
 => []

but Shellwords can:

 require 'shellwords'
 Shellwords.shellwords(s)
 => ["one", "two  with quotes", "three "]