http://qs321.pair.com?node_id=11112813


in reply to regex for nested "<"/">'

In the regex, changing \d*+ to \d++ fixes it, although I have to admit I don't see why yet, it'll take a bit more staring at it to figure that out... Anyway: WebPerl Regex Tester Link

Personally, I'd use Regexp::Common for this kind of task:

use warnings; use strict; use Regexp::Common 2013030901 qw/balanced/; my $re = qr/$RE{balanced}{-parens=>'<>'}/; print $re, "\n"; my @cases = ( "<1>" ,"<1,2>" ,"<1,2,<3,4>,5,6>" ); for my $case (@cases) { print $case, " ", $case =~ $re ? "matches: '$1'\n" : "doesn't match\n"; } __END__ (?^:((?:\<(?:(?>[^\<\>]+)|(?-1))*\>))) <1> matches: '<1>' <1,2> matches: '<1,2>' <1,2,<3,4>,5,6> matches: '<1,2,<3,4>,5,6>'