| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Thu, 04 Feb 2021 10:19:48 +0000 | |
| changeset 823 | e42a180e2e39 | 
| parent 753 | 30ea6b01db46 | 
| permissions | -rwxr-xr-x | 
| 753 | 1 | #!/usr/bin/env python3 | 
| 745 | 2 | |
| 49 | 3 | import re | 
| 4 | import sys | |
| 5 | ||
| 613 | 6 | # case of catastrophic backtracking in Python | 
| 558 | 7 | # | 
| 613 | 8 | # regex: (a*)*b | 
| 9 | # strings: aa...a | |
| 558 | 10 | # | 
| 420 
25bc57b32efa
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
411diff
changeset | 11 | # call with timing as: | 
| 
25bc57b32efa
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
411diff
changeset | 12 | # | 
| 742 | 13 | # time ./catastrophic.py 20 | 
| 420 
25bc57b32efa
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
411diff
changeset | 14 | |
| 
25bc57b32efa
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
411diff
changeset | 15 | # counter n given on the command line | 
| 49 | 16 | cn = sys.argv[1] | 
| 17 | ||
| 613 | 18 | # calling the matching function | 
| 19 | s = ("a" * int(cn))
 | |
| 20 | m = re.match('(a*)*b' , s) 
 | |
| 49 | 21 | |
| 753 | 22 | print(s) | 
| 23 | print(m) |