From: William James Date: 2006-12-21T05:20:12+09:00 Subject: Re: Grabbing quoted substrings Bil Kleb wrote: > OK, I give up, what's the elegant method to > grab the quoted substrings in the following, > > a = 'variables="x", "y", "z", "rho", "u", "v", "w", "p/pinf", "s", "mach"' > > I want an array like, > > ["x", "y", "z", ..., "mach"] > > The methods I've come up with so far are > embarrassingly hideous. > > Thanks, > -- > Bil Kleb > http:// a = 'variables="x", "foo\"bar", "\"\"", "rho", "u", "p/pinf", "mach"' x = a.scan( /"((?:\\.|.)*?)"/ ).flatten p x puts x --- output ----- ["x", "foo\\\"bar", "\\\"\\\"", "rho", "u", "p/pinf", "s", "mach"] x foo\"bar \"\" rho u p/pinf s mach