Phrogz
1/30/2008 7:36:00 PM
On Jan 30, 12:28 pm, Cheri Ruska <liquid_ra...@yahoo.com> wrote:
> I am trying to parse out the string:
>
> My dog "ate" my "math homework" and "my cat"
>
> into the array:
>
> [My, dog, ate, my, math homework, and, my cat]
irb(main):001:0> str = 'My dog "ate" my "math homework" and "my cat"'
=> "My dog \"ate\" my \"math homework\" and \"my cat\""
irb(main):002:0> str.scan( /"[^"]+"|\w+/ ).map{ |w| w.gsub '"', '' }
=> ["My", "dog", "ate", "my", "math homework", "and", "my cat"]
Not a very robust solution. Won't handle a \" in the middle of some
quotes, or an incorrectly unpaired quote.