Problem with SRE's regular expressions
Christophe Delord
christophe.delord at free.fr
Mon Mar 4 16:41:38 EST 2002
Thanks for your explanation!
In my real program, I had a more complex regexp. I need to match text
enclosed in << ... >>
I first have used such an expression : <<([^>]|>[^>])*>>
but I prefered <<.*?>> because it is more readable.
I'll listen to the advice and use my old regexp to see how faster it is
this way ;-)
Thanks,
Christophe.
Fredrik Lundh wrote:
> Christophe Delord wrote:
>
>>I'm using regular expressions in python in a parser generator. I have
>>some troubles with the module named 're'. In fact it uses the 'sre'
>>module. When I explicitly use the old 'pre' module it works fine.
>>So my problem is when big strings are scanned using non greedy operator
>>(for example ".*?") 'sre' seems to be recursivle and python stack limit
>>is exceeded.
>>
>
> the SRE engine is trying to tell you that you're using the wrong
> tool for the task, and probably should think of a better way to
> do the right thing...
>
>
>>big_string = "<" + "that's a very very big string!"*1000 + ">"
>>
>>if re.match('<.*?>', big_string):
>>
>
> here's the same thing, without any backtracking:
>
> if re.match('<[^>]*>', big_string):
>
> under PRE, it's about an order of a magnitude faster than your
> version. and SRE is over twice as fast as PRE on this one...
>
> </F>
>
>
--
Christophe Delord
http://christophe.delord.free.fr/
More information about the Python-list
mailing list