From: Robert Klemme Date: 2011-04-07T16:13:13+09:00 Subject: Re: Match a pattern multiple times, returning matches, captures and offset? On Thu, Apr 7, 2011 at 1:58 AM, 7stud -- wrote: > You can also get the relative offset like this: > > str = "_foo_ _bar_" > > str.scan(/_(\w+)_/) do |curr_match| >  md = Regexp.last_match >  whole_match = md[0] >  captures = md.captures >  captures.each do |capture| >    p [whole_match, capture, whole_match.index(capture)] > end That's nice! I wasn't aware of this. Thanks for sharing! I also just read this in the docs: "Note that the last_match is local to the thread and method scope of the method that did the pattern match." So forget my point about $~ being safer. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/