From: Xavier Noria Date: 2007-03-16T23:21:17+09:00 Subject: Re: Splitting A String On Mar 16, 2007, at 3:14 PM, Xavier Noria wrote: > On Mar 16, 2007, at 2:35 PM, Andrew Stewart wrote: > >> Hello, >> >> What's a (good) way to convert this: >> >> 'a quick "brown fox" jumped "over the lazy" dog' >> >> into this: >> >> [ 'a', 'quick', 'brown fox', 'jumped', 'over the lazy', 'dog' ] > > Can quotes be escaped? If not there's a simple regexp that does the > job: > > str = 'a quick "brown fox" jumped "over the lazy" dog' > puts str.scan(/"([^"]*)"|(\w+)/).flatten.select {|s| s} Heh, reading it I recalled there's a more specific idiom for that last select: str = 'a quick "brown fox" jumped "over the lazy" dog' puts str.scan(/"((?:\\.|[^"])*)"|(\w+)/).flatten.compact -- fxn