Cancel or timeout a long running regular expression

Nobody nobody at nowhere.com
Sat Sep 17 15:00:53 EDT 2011


On Fri, 16 Sep 2011 18:01:27 -0400, Terry Reedy wrote:

> Now, can you write that as a heuristic *algorithm*
> def dangerous_re(some_re):?

	return re.search(r'\\\d', some_re) is not None

That will handle the most extreme case ;)

If the OP is serious about analysing regexps, sre_parse.parse() will
decompose a regexp to a more convenient form.

However, I wouldn't rely upon being able to catch every possible bad case.
The only robust solution is to use a separate process (threads won't
suffice, as they don't have a .kill() method).




More information about the Python-list mailing list