From: "Eregon (Benoit Daloze)" Date: 2012-07-27T18:54:40+09:00 Subject: [ruby-core:46806] [ruby-trunk - Feature #6802] String#scan should have equivalent yielding MatchData Issue #6802 has been updated by Eregon (Benoit Daloze). =begin You can use (({String#scan})) with the block form and (({$~})) (as well as other Regexp-related globals) for this: > text="x:1 y:12 ; x:33 y:2" > text.scan(/x:(?\d+) y:(?\d+)/) { p [$~[:x],$~[:y]] } ["1", "12"] ["33", "2"] Please check your Regexp and give an example of (({text})) next time. =end ---------------------------------------- Feature #6802: String#scan should have equivalent yielding MatchData https://bugs.ruby-lang.org/issues/6802#change-28480 Author: prijutme4ty (Ilya Vorontsov) Status: Open Priority: Normal Assignee: Category: Target version: Ruby should have method to obtain not an array of arrays but of MatchData objects. It can help in obtaining named groups: pattern = /x: (?\d+) y:(?\d+)/ polygon = [] text.scan_for_pattern(pattern){|m| polygon << Point.new(m[:x], m[:y]) } Not to break existing code we need unique name. Ideas? May be #each_match -- http://bugs.ruby-lang.org/