[issue23541] Re module's match() fails to halt on a particular input

Serhiy Storchaka report at bugs.python.org
Fri Feb 27 21:39:30 CET 2015


Serhiy Storchaka added the comment:

Minimal example for your case is

re.match(r'(\w+\s*)+\s+\d+', 'Compiling Regular Patterns to Sequential Machines')

It doesn't halt, it just needs too long time to finish. Your should rewrite the regular expression to avoid catastrophic backtracking (http://www.regular-expressions.info/catastrophic.html). For example rewrite the start of your expression as

re.match(r'\w[\w\s]*\s\d+', 'Compiling Regular Patterns to Sequential Machines')

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23541>
_______________________________________


More information about the Python-bugs-list mailing list