| author | Christian Urban <urbanc@in.tum.de> | 
| Thu, 08 Mar 2018 12:32:50 +0000 | |
| changeset 171 | 2545bdf5ace0 | 
| parent 156 | 6b9542fc9dc4 | 
| permissions | -rw-r--r-- | 
| 155 | 1 | #!/usr/bin/env python | 
| 2 | import re | |
| 3 | import sys | |
| 4 | ||
| 5 | # case of catastrophic backtracking in Python | |
| 6 | # | |
| 156 | 7 | # regex: (a*)*b | 
| 8 | # strings: aa...a | |
| 155 | 9 | # | 
| 10 | # call with timing as: | |
| 11 | # | |
| 12 | # > time ./catastrophic.py 20 | |
| 13 | ||
| 14 | # counter n given on the command line | |
| 15 | cn = sys.argv[1] | |
| 16 | ||
| 156 | 17 | # calling the matching function | 
| 18 | s = ("a" * int(cn))
 | |
| 19 | m = re.match('(a*)*b' , s) 
 | |
| 155 | 20 | |
| 156 | 21 | print s |