> 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"]
>
a.scan(/"([^"]+)"/).flatten
No need to use flatten if you don't use the (unnecessary) grouping:
a.scan( /"[^"]+"/ )
or
a.scan( /".+?"/ )
(Both, of course, assuming no escaped backslashes in the content. It's
not hard to come up with a regexp that accepts those, though at some
point perhaps Ara's eval solution is easier.)
ยทยทยท
From: mitchell
Gavin Kistner wrote:
From: mitchell
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"]
a.scan(/"([^"]+)"/).flatten
No need to use flatten if you don't use the (unnecessary) grouping:
a.scan( /"[^"]+"/ )
or
a.scan( /".+?"/ )
(Both, of course, assuming no escaped backslashes in the content. It's
not hard to come up with a regexp that accepts those, though at some
point perhaps Ara's eval solution is easier.)
Though that will capture the surrounding quotes as well, which was not specified in the requirements.
Tom Werner