Perl regex help
Dear Lazyweb, please put me out of my misery.
I have a string that looks something like:
a b c foo {0 1 2} fred {3 4 5} {{5 4 3} {2 1 0}} quux
I want to output:
a b c foo {0 1 2} fred {3 4 5} {{5 4 3} {2 1 0}} quux
(actually I want each line to be an array element, but that's obviously easy)
Can I do this with a Perl regex? Originally I thought I was going to have to walk the string like I would in C, but some playing around (and local help) got me to:
my $match = qr/(?:\s*[^\{\}\s]+\s*|\{(?R)\})/; while ($cur =~ m/($match)\s+(.*)/o) { print $1, "\n"; $cur = $2; }
which sort of gets me there, except I get
{0 1 2} fred {3 4 5} {{5 4 3} {2 1 0}}
as one line instead of 4.
What obvious thing am I missing here?