develooper Front page | perl.perl5.porters | Postings from May 2004

Re: slow regex?

Thread Previous
From:
Andy Lester
Date:
May 24, 2004 20:46
Subject:
Re: slow regex?
Message ID:
20040525034624.GB16536@petdance.com
On Tue, May 25, 2004 at 12:23:01AM +0100, Dave Mitchell (davem@iabyn.com) wrote:
> This regex takes 2.5 secs on my machine to fail to match (5.8.4 and
> bleed):
> 
>     $_ = <<'EOF';
>     AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
>     BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
>     EOF
> 
>     print "matched\n" if /.*?A.*?B+\s+X/s;

There's no need for that .*? at the beginning.  It's always going to
match (although I"m not sure what that ? is gonna do after a *).

Drop the leading .* and you're happy.


-- 
Andy Lester => andy@petdance.com => www.petdance.com => AIM:petdance

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