Just want to provide more data here, as it may not be clear how dangerous processing raw regular expressions can be:
clint@clint-HP:~/src$ cat /tmp/test.py import re import sys
n = int(sys.argv[1])
x = re.compile(('a?' * n) + ('a' * n)) print bool(x.match('a' * n)) clint@clint-HP:~/src$ time python /tmp/test.py 20 True
real 0m0.085s user 0m0.080s sys 0m0.004s clint@clint-HP:~/src$ time python /tmp/test.py 25 True
real 0m2.062s user 0m2.048s sys 0m0.012s clint@clint-HP:~/src$ time python /tmp/test.py 30 ^CTraceback (most recent call last): File "/tmp/test.py", line 7, in <module> print bool(x.match('a' * n)) KeyboardInterrupt
real 0m22.336s user 0m22.284s sys 0m0.008s clint@clint-HP:~/src$ time python /tmp/test.py 26 True
real 0m4.165s user 0m4.148s sys 0m0.008s clint@clint-HP:~/src$ time python /tmp/test.py 27 True
real 0m8.501s user 0m8.456s sys 0m0.028s
Note that with every added character, the CPU time doubles.
Just want to provide more data here, as it may not be clear how dangerous processing raw regular expressions can be:
clint@clint- HP:~/src$ cat /tmp/test.py
import re
import sys
n = int(sys.argv[1])
x = re.compile(('a?' * n) + ('a' * n)) HP:~/src$ time python /tmp/test.py 20
print bool(x.match('a' * n))
clint@clint-
True
real 0m0.085s HP:~/src$ time python /tmp/test.py 25
user 0m0.080s
sys 0m0.004s
clint@clint-
True
real 0m2.062s HP:~/src$ time python /tmp/test.py 30
user 0m2.048s
sys 0m0.012s
clint@clint-
^CTraceback (most recent call last):
File "/tmp/test.py", line 7, in <module>
print bool(x.match('a' * n))
KeyboardInterrupt
real 0m22.336s HP:~/src$ time python /tmp/test.py 26
user 0m22.284s
sys 0m0.008s
clint@clint-
True
real 0m4.165s HP:~/src$ time python /tmp/test.py 27
user 0m4.148s
sys 0m0.008s
clint@clint-
True
real 0m8.501s
user 0m8.456s
sys 0m0.028s
Note that with every added character, the CPU time doubles.