On Oct 1, 5:37 am, Mintcake <t...@skelding.co.uk> wrote:
> I wouldd be grateful to anyone who can shed some light on the
> unexpected
> results from the regex in the following program.
>
> #!/usr/local/bin/perl -l
>
> use strict;
>
> my $y = ' href="/foo/bar?d=1&c=2&f=1&cards=1" x="123"';
>
> for ($y =~ /(\s+\w+=['"](.*?)["'])/gs)
> {
> print "1) $_";
> print "2) [$1][$2]";
>
> my $x = /(\w+)=['"](.*)["']/;
> print "3) [$x] [$1][$2]";
>
> my $x = /(\w+)=['"](.*)["']/;
> print "4) [$x] [$1][$2]";
>
> my $x = /(\w+)=['"](.*)["']/;
> print "5) [$x] [$1][$2]";
>
> print "";}
>
> __END__
>
> The results I get are as follows
>
> 1) href="/foo/bar?d=1&c=2&f=1&cards=1"
> 2) [ x="123"][123]
> 3) [1] [href][/foo/bar?d=1&c=2&f=1&cards=1]
> 4) [1] [href][/foo/bar?d=1&c=2&f=1&cards=1]
> 5) [1] [href][/foo/bar?d=1&c=2&f=1&cards=1]
>
> 1) /foo/bar?d=1&c=2&f=1&cards=1
> 2) [href][/foo/bar?d=1&c=2&f=1&cards=1]
> 3) [] [href][/foo/bar?d=1&c=2&f=1&cards=1]
> 4) [] [href][/foo/bar?d=1&c=2&f=1&cards=1]
> 5) [] [=2&f=][]
This is a bug for sure. Notice that '=2&f=' is the same length as
'cards'. How it ends up at that offset im not sure and I havent
debugged it to see whats up.
The good news is that I already fixed this for 5.10, although its hard
to say which fix was responsible, there were a number related to
capturing and rollbacks and the like done in the 5.9.x line.
The bad news is that the patch is highly unlikely to be back ported to
5.8.x
Interesting bug tho. Cheers.
Yves