#!/usr/bin/env pythonimport reimport sys# case of catastrophic backtracking in Python## regex: (a?){n} a{n}# strings: aa...## call with timing as:## > time ./catastrophic.py 20# counter n given on the command linecn = sys.argv[1]# constructing the regexr1 = '((a?){%s})' % cnr2 = 'a{%s}' % cn# calling the matching functionm = re.match(r1 + r2 , "a" * int(cn)) print m.group(0)