Problem with SRE's regular expressions
Fredrik Lundh
fredrik at pythonware.com
Mon Mar 4 15:49:58 EST 2002
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>
More information about the Python-list
mailing list