| changeset 964 | d3e22099963d |
| parent 963 | 4e3f7b3574a9 |
| child 965 | e7dbebf43ac3 |
| 963:4e3f7b3574a9 | 964:d3e22099963d |
|---|---|
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) |