Hoosgot

Send your wishes and desires out into the ether.

Hoosgot header image 2

Perl regex help

November 28th, 2008 · No Comments

http://www.earth.li/~noodles/blog/2008/11/perl-regex-help.html asks Hoosgot,

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*|\{(?R)\})/; while ($cur =~ m/($match)\s+(.*)/o) { print $1, “\n”; $cur =

Visit the blog to lend your wisdom, or you can comment below.

Tags: Uncategorized

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment