"NAKAMURA, Hiroshi" <nahi / keynauts.com> schrieb im Newsbeitrag news:40F542B0.1090707 / keynauts.com... > Hi, > > Michael Weller wrote: > > Can anybody help me with following, it seems like I can find a solution > > that's shorter than 50LOC and I thought there must be a smarter way to > > do it... > > 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 ... > > Is quoting " needed? > > 0% ruby -rcsv -e 'p CSV.parse_line(%["this is" "my text"], ?\s)' > ["this is", "my text"] > > 0% ruby -rcsv -e 'p CSV.parse(%["this is" "my text"|foo bar], ?\s, ?|)' > [["this is", "my text"], ["foo", "bar"]] Very nice! I usually use something like this for similar cases: rx = %r{ (?:"(?:[^\\"]|\\.)*") | (?:'(?:[^\\']|\\.)*') | \S+ }x str.scan rx Regards robert