Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by haukex (Chancellor)
on Feb 11, 2020 at 20:51 UTC ( #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
Node Status?
node history
Node Type: note [id://11112813]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2020-03-30 18:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    To "Disagree to disagree" means to:









    Results (175 votes). Check out past polls.

    Notices?