From: Robert Klemme Date: 2004-08-18T19:31:01+09:00 Subject: Regexp scanning with MatchData (Re: multiple regexp matches) "Austin Ziegler" schrieb im Newsbeitrag news:9e7db91104081713254f2eb39e@mail.gmail.com... > This should do what you want. > > -austin > > str = ' ... ' > re = /(<(\/?)span>)/i > > str.scan(re) # => [["", ""], ["", "/"], ["", "/"]] > > matches = [] > str.scan(re) do > matches << Regexp.last_match > end > > matches.each do |match| > match.captures.each_with_index do |capture, ii| > soff, eoff = match.offset(ii + 1) > puts %Q("#{capture}" #{soff} .. #{eoff}) > end > end > While that works, isn't it ridiculous that one has to resort to a class method ("Regexp.last_match")? I mean, there should rather be something like /o/.each( "foo" ) do |md| # md is MatchData end Or even /o/.matcher( "foo" ).each do |md| # md is MatchData end That way Matcher could implement Enumerable. Sounds like a candidate for a RCR. Any comments? robert