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