ruby-1.9.2-p180 :003 > result = "test string".match(/(?<mtch>test)/) => #<MatchData "test" mtch:"test"> ruby-1.9.2-p180 :011 > result["mtch"] => "test" ruby-1.9.2-p180 :012 > result["fail"] IndexError: undefined group name reference: fail from (irb):12:in `[]' from (irb):12 from /Users/jeremysmith/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'
解决方法
result.names.include? 'mtch' # => true result.names.include? 'fail' # => false