From: George Ogata Date: 2004-07-15T12:57:19+09:00 Subject: Re: Split quoted text Charles Mills writes: > On Jul 14, 2004, at 5:51 AM, Michael Weller wrote: > >> David A. Black wrote: >> >>> Hi -- >>> >>> On Wed, 14 Jul 2004, Michael Weller wrote: >>> >>> >>>> My input would be something like "\this is\" \"my text\"" and I want >>>> to have an array containing ["\"this is\"", "\"my text\""]. >>>> I know it can't be that hard, but ... >>>> >>> >>> p '"this is" "my text"'.scan(/"[^"]+"/) >>> # => ["\"this is\"", "\"my text\""] > On that note, if you have escaped quotes you can use the following: > p '"he said \"hello\"" "field"'.scan(/"(?:\\.|[^"])*?"/) > # => ["\"he said \\\"hello\\\"\"", "\"field\""] There's also shellwords: irb(main):001:0> require 'shellwords' => true irb(main):002:0> Shellwords.shellwords('"he said \\"hello\\"" "field"') => ["he said \"hello\"", "field"]