progs/catastrophic/catastrophic.py
changeset 741 6512884e03b4
parent 701 81377a3eb717
child 742 155426396b5f
equal deleted inserted replaced
740:cdfc278e37b9 741:6512884e03b4
       
     1 #!/usr/bin/env python
       
     2 import re
       
     3 import sys
       
     4 
       
     5 # case of catastrophic backtracking in Python
       
     6 #
       
     7 # regex: (a*)*b
       
     8 # strings: aa...a
       
     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 
       
    17 # calling the matching function
       
    18 s = ("a" * int(cn))
       
    19 m = re.match('(a*)*b' , s) 
       
    20 
       
    21 print s
       
    22 print m