develooper Front page | perl.perl5.porters | Postings from August 2008

Re: Wrong RE match in 5.10.0

Thread Previous
Moritz Lenz
August 25, 2008 09:05
Re: Wrong RE match in 5.10.0
Message ID:
David Nicol wrote:
>>>>> $str = "x" x (1024 * 100);
>>>>> if ($str =~ /^(.)(\1*)\z/) {
>>>>>   print "$1 ", length($2), "\n";
>>>>> }
>>>>> else {
>>>>>   print "no match\n";
>>>>> }
>>>>> __END__
> but why is this recursing at all?  It doesn't need to backtrack.
> Could the * be made to simply loop instead of recursing?

I think "recursion" is misleading. * translates to {0,32767} and
formerly the regex engine was recursive.

(slightly OT: this regex could be optimized if we had a solver for
algebraic equations. we know that length(.*) == length($1), and that the
sum of those lengths equals the length of the string. Thus .* has to
match length($_)/2 characters. But I guess it's pretty hard to actually
implement that)


Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About