From: botp Date: 2010-07-09T02:01:52+09:00 Subject: Re: Regular expressions, capture repeated groups On Fri, Jul 9, 2010 at 12:38 AM, Iain Barnett wrote: > Thanks for that. That would certainly work to a degree, much better than my current alternative, but it nullifies the usefulness of named captures. For example, I can't call > > $ md1[:first] wait till you call the 21st ;-) > and get back all the matches for the (? ) grouping, which would be phenomenally useful, because scan returns arrays of strings and not matchdata. > waxman hinted the $~ try eg, s #=> "The the quick brown fox fox jumped over the lazy dog dog." m=[] #=> [] s.scan(/((\w+) +\2)/i){|x| m << $~} #=> "The the quick brown fox fox jumped over the lazy dog dog." m.size #=> 3 m[0] #=> # m[0].offset 0 #=> [0, 7] m[0].offset .... and so fort.. best regards -botp