Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: regex for nested "<"/">'

by haukex (Archbishop)
on Feb 11, 2020 at 20:51 UTC ( [id://11112813]=note: print w/replies, xml ) Need Help??


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>'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11112813]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-29 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found