Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: slow regular expressions

by ikegami (Patriarch)
on Aug 08, 2006 at 05:18 UTC ( #566074=note: print w/replies, xml ) Need Help??


in reply to slow regular expressions

It attemps to match and backtracks when it can't find a match. Here's a sample of the matches (one per line) the regexp engine attempts.
1) a*->"a"x61, a*->"", a*->"", a*->"", ... a*->"", [b]->fail 2) a*->"a"x60, a*->"a", a*->"", a*->"", ... a*->"", [b]->fail 3) a*->"a"x60, a*->"", a*->"a", a*->"", ... a*->"", [b]->fail 4) a*->"a"x60, a*->"", a*->"", a*->"a", ... a*->"", [b]->fail . . . 32) a*->"a"x60, a*->"", a*->"", a*->"", ... a*->"a", [b]->fail 33) a*->"a"x60, a*->"", a*->"", a*->"", ... a*->"", [b]->fail 34) a*->"a"x59, a*->"aa", a*->"", a*->"", ... a*->"", [b]->fail 35) a*->"a"x59, a*->"a", a*->"a", a*->"", ... a*->"", [b]->fail 36) a*->"a"x59, a*->"a", a*->"", a*->"a", ... a*->"", [b]->fail . . . 64) a*->"a"x59, a*->"a", a*->"", a*->"", ... a*->"a", [b]->fail 65) a*->"a"x59, a*->"a", a*->"", a*->"", ... a*->"", [b]->fail 66) a*->"a"x59, a*->"", a*->"aa", a*->"", ... a*->"", [b]->fail 67) a*->"a"x59, a*->"", a*->"a", a*->"a", ... a*->"", [b]->fail . . . 95) a*->"a"x59, a*->"", a*->"a", a*->"", ... a*->"a", [b]->fail . . .

The character class [b] is necessary because a plain b would trigger optimizations in the regexp engine. The optimization would cause it to scan for the location of b chars in the string to match. Finding none, it would exit immediately.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://566074]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2022-05-18 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (68 votes). Check out past polls.

    Notices?