From: Joe Van Dyk Date: 2005-03-08T06:04:48+09:00 Subject: matching regular expression I have a string that contains a list of keys and values. "key1: a_value, key2: another_value, key3: yet_another_value" I have an array of ["key1", "key2", "key3"]. I'd like to loop through and find all the values in the string that have a key in the key array. My first attempt was: keys = ["key1", "key2", "key3"] my_str = "key1: a_value, key2: another_value, key3: yet_another_value" keys.each do |key| my_str =~ Regexp.new("#{key}: \\w+") puts "the value for #{key} was #{$1}" end But that's not working properly. Any ideas? Thanks, Joe