From: Andrew Stewart Date: 2008-03-20T19:33:59+09:00 Subject: Re: Split string at spaces, but not when inside quotation marks? On 19 Mar 2008, at 10:26, Sebastian Hungerecker wrote: > Peter Bunyan wrote: >> Is there already a built-in method to do this > > require 'shellwords' > Shellwords.shellwords 'Hello "wo rld" how "are \" you today"' > => ["Hello", "wo rld", "how", "are \" you today"] Or you can pretend it's CSV: $ irb >> require 'csv' => true >> s = 'the "quick brown" fox jumped "over a lazy" dog' => "the "quick brown" fox jumped "over a lazy" dog" >> CSV.parse_line s, ' ' => ["the", "quick brown", "fox", "jumped", "over a lazy", "dog"] Unfortunately it doesn't handle the pesky backslash in Sebastian's example above. >> s = 'Hello "wo rld" how "are \" you today"' => "Hello "wo rld" how "are \\" you today"" >> CSV.parse_line s, ' ' => [] Oh well! Cheers, Andy ------- AirBlade Software http://airbladesoftware.com