progs/re.rb
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 02 Oct 2013 01:02:50 +0100
changeset 121 43c116860e47
parent 93 progs/re-internal.rb@4794759139ea
child 226 e3c454e31224
permissions -rw-r--r--
updated

# provided by Daniel Baldwin

nums = (1..100)

#iterate through the nums 1-100
nums.each do |i|

	start_time = Time.now
	string = "a" * i

	#create a new regular expression based on current value of i
	re = Regexp.new(/((a?){#{i}})(a{#{i}})/)

        re.match(string)
	#if re.match(string)
	#	puts "matched string  a * #{i} with regex #{re}"
	#else
	#	puts "unmatched string a * #{i} with regex #{re}"
	#end
	
  puts "#{i} %.5f" % (Time.now - start_time)
end