Re: re bug
From: Gustavo Niemeyer (niemeyer_at_conectiva.com)
Date: 10/05/04
- Next message: Josiah Carlson: "Re: New to Python: Features"
- Previous message: Josiah Carlson: "Re: New to Python: Features"
- In reply to: Thomas Rast: "Re: re bug"
- Next in thread: Thomas Rast: "Re: re bug"
- Reply: Thomas Rast: "Re: re bug"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 5 Oct 2004 14:22:20 -0300 To: python-list@python.org
> '''
> (?:^|\ )
> (?P<ALLES>
> (?:
> [^/ ]*/[^/ ]*/
> (?: # why a group?
> cn
> (?: :[^/ #]+ )*
[...]
That's not the same regular expression. You must escape whitespaces
when using re.VERBOSE.
> Judging from the number of '*' and '+' quantifiers, the long search
> time may be due to excessive backtracking as the regexp engine tries
> to find a match.
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.
Try this example:
re.search("a(((.)*c)*d)*e", "abcdf"*20)
Also, if you're curious enough, try to replace 20 by 10, and
increase it one at a time.
Btw, the only reason that the OP's expression didn't got stuck
in the first two test cases is because the expression matched.
-- Gustavo Niemeyer http://niemeyer.net
- Next message: Josiah Carlson: "Re: New to Python: Features"
- Previous message: Josiah Carlson: "Re: New to Python: Features"
- In reply to: Thomas Rast: "Re: re bug"
- Next in thread: Thomas Rast: "Re: re bug"
- Reply: Thomas Rast: "Re: re bug"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|