From: "prijutme4ty (Ilya Vorontsov)" Date: 2012-07-27T16:30:41+09:00 Subject: [ruby-core:46802] [ruby-trunk - Feature #6802] String#scan should have equivalent yielding MatchData Issue #6802 has been updated by prijutme4ty (Ilya Vorontsov). Simple implementation: class String def each_match(pattern, &block) return Enumerator.new(self, :each_match, pattern) unless block_given? text = self m = text.match(pattern) while m yield m text = text[m.end(0)..-1] m = text.match(pattern) end end end ---------------------------------------- Feature #6802: String#scan should have equivalent yielding MatchData https://bugs.ruby-lang.org/issues/6802#change-28472 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/