progs/re.rb
changeset 121 43c116860e47
parent 93 4794759139ea
child 226 e3c454e31224
equal deleted inserted replaced
120:3e71efb25ce9 121:43c116860e47
       
     1 # provided by Daniel Baldwin
       
     2 
       
     3 nums = (1..100)
       
     4 
       
     5 #iterate through the nums 1-100
       
     6 nums.each do |i|
       
     7 
       
     8 	start_time = Time.now
       
     9 	string = "a" * i
       
    10 
       
    11 	#create a new regular expression based on current value of i
       
    12 	re = Regexp.new(/((a?){#{i}})(a{#{i}})/)
       
    13 
       
    14         re.match(string)
       
    15 	#if re.match(string)
       
    16 	#	puts "matched string  a * #{i} with regex #{re}"
       
    17 	#else
       
    18 	#	puts "unmatched string a * #{i} with regex #{re}"
       
    19 	#end
       
    20 	
       
    21   puts "#{i} %.5f" % (Time.now - start_time)
       
    22 end