clueless newbie has asked for the wisdom of the Perl Monks concerning the following question:
I've taken this from Conway's "Everything You Know About Regexes Is Wrong", but I can't get it to behave.
#!/usr/bin/env perl use 5.01800; use warnings; my @cases=( "<1>" ,"<1,2>" ,"<1,2,<3,4>,5,6>" ); my $re=qr{(?x) (?&LIST) (?(DEFINE) (?<LIST> < (?&ITEM) (?: , (?&ITEM))*+ > ) (?<ITEM> \d*+ | (?&LIST) ) ) }; for my $case (@cases) { say qq{$case\n}, $case =~ qr{$re} ? "matches: '$&'" : "doesn't match"; }; __END__
which yields
perl Conway_01.pl <1> matches! <1> <1,2> matches! <1,2> <1,2,<3,4>,5,6> matches! <3,4> !!!! shouldn't this be <1,2,<3,4>,5,6>
What have I got wrong?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: regex for nested "<"/">'
by TheDamian (Vicar) on Feb 12, 2020 at 09:31 UTC | |
by shadowsong (Pilgrim) on Feb 12, 2020 at 22:26 UTC | |
Re: regex for nested "<"/">'
by choroba (Cardinal) on Feb 11, 2020 at 21:24 UTC | |
Re: regex for nested "<"/">'
by haukex (Archbishop) on Feb 11, 2020 at 20:51 UTC | |
Re: regex for nested "<"/">'
by clueless newbie (Curate) on Feb 12, 2020 at 15:12 UTC | |
by jo37 (Curate) on Feb 12, 2020 at 21:42 UTC | |
by clueless newbie (Curate) on Feb 12, 2020 at 22:20 UTC | |
by tybalt89 (Monsignor) on Feb 13, 2020 at 17:00 UTC |