re bug

Thomas Rast foo.bar at freesurf.ch.invalid
Tue Oct 5 19:58:03 CEST 2004


Gustavo Niemeyer <niemeyer at conectiva.com> writes:

> That's not the same regular expression. You must escape whitespaces
> when using re.VERBOSE.

As far as I can see, I did, except in character classes, and quoting
from the 're' manual:

] X
] VERBOSE
] This flag allows you to write regular expressions that look
] nicer. Whitespace within the pattern is ignored, except when in a
] character class or preceded by an unescaped backslash [...]

> The problem is not just the number of repeating qualifiers, but
> the nesting of them. Nesting repeating qualifiers deeply is a good
> way to kill regular expression engines.
[...]

I actually tried the example stated in 'man perlre', translated to
python:

>>> import re
>>> r=re.compile('((a{0,5}){0,5})*[c]')
>>> r.match('a'*10)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
RuntimeError: maximum recursion limit exceeded

but apparently there are ways to nest the backtracking without hitting
recursion limits.

- Thomas

-- 
If you want to reply by mail, substitute my first and last name for
'foo' and 'bar', respectively, and remove '.invalid'.



More information about the Python-list mailing list