re question

Darrell darrell at dorb.com
Sat Oct 16 23:36:41 EDT 1999


If you want to kill some real time try this:

import re
s='aaxx'*9999
re.findall('aa.*?bb', s)

My users can input such a pattern and find them self's stuck. Been playing
with ways to detect this and avoid the worst case runtime. Maybe something
about it in the "Mastering Regular Expression" book  ?

Attached a half baked swag at a solution. Split the pattern on '.*?' then
search from the end of the pattern to the front. And simulate the .*?

Something like this:
import myRe
s='aaxx'*9999
myRe.findallOptimize('aa.*?bb', 0, s)

I'd be happy with setting a time out and error callback on re.

--Darrell
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: myRe.py
URL: <http://mail.python.org/pipermail/python-list/attachments/19991016/a685bc78/attachment.ksh>


More information about the Python-list mailing list