Pathological regular expression

Aaron Brady castironpi at gmail.com
Sat Apr 11 12:54:10 EDT 2009


On Apr 11, 10:07 am, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> On Thu, 09 Apr 2009 02:56:00 -0700, David Liang wrote:
> > Hi all,
> > I'm having a weird problem with a regular expression (tested in 2.6 and
> > 3.0):
>
> > Basically, any of these:
> > _re_comments = re.compile(r'^(([^\\]+|\\.|"([^"\\]+|\\.)*")*)#.*$')
> > _re_comments = re.compile(r'^(([^#]+|\\.|"([^"\\]+|\\.)*")*)#.*$')
> > _re_comments = re.compile(r'^(([^"]+|\\.|"([^"\\]+|\\.)*")*)#.*$')
>
> > followed by for example,
> > line = r'~/.[m]ozilla/firefox/*.default/chrome'
> > print(_re_comments.sub(r'\1', line))
>
> > ...hangs the interpreter.
>
> I can confirm the first one hangs the interpreter in Python 2.5 as well.
> I haven't tested the other two.
>
> To my mind, this is a bug in the RE engine. Is there any reason to not
> treat it as a bug?
>
> --
> Steven

How long does it take on a short example?



More information about the Python-list mailing list