From: Phrogz Date: 2008-01-31T04:40:02+09:00 Subject: Re: Parsing a string with quotes On Jan 30, 12:28 pm, Cheri Ruska 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.