changeset 965 | 94f5cce73a4f |
parent 964 | da1f8c033b8e |
child 966 | 4189cb63e5db |
964:da1f8c033b8e | 965:94f5cce73a4f |
---|---|
1 #!/usr/bin/env python3 |
|
2 |
|
3 import re |
|
4 import sys |
|
5 |
|
6 # case of catastrophic backtracking in Python |
|
7 # |
|
8 # regex: (a*)*b |
|
9 # strings: aa...a |
|
10 # |
|
11 # call with timing as: |
|
12 # |
|
13 # time ./catastrophic.py 20 |
|
14 |
|
15 # counter n given on the command line |
|
16 cn = sys.argv[1] |
|
17 |
|
18 # calling the matching function |
|
19 s = ("a" * int(cn)) |
|
20 m = re.match('(a*)*b' , s) |
|
21 |
|
22 print(s) |
|
23 print(m) |