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

Re: Wrong RE match in 5.10.0

Thread Previous
From:
Moritz Lenz
Date:
August 25, 2008 09:05
Subject:
Re: Wrong RE match in 5.10.0
Message ID:
20080825160420.24942.qmail@lists.develooper.com
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)

Moritz

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About