From: Brian Candler Date: 2011-04-06T03:07:41+09:00 Subject: Re: Match a pattern multiple times, returning matches, captures and offset? String#scan with a block may do what you want: >> "_foo_ _bar_".scan(/_(\w+)_/) { |x| puts "Offset #{$`.size}, captures #{x.inspect}" } Offset 0, captures ["foo"] Offset 6, captures ["bar"] => "_foo_ _bar_" But it doesn't give you offsets to the individual captures, just to the start of the whole match. (You also get the full match in $& and the rest of the string after the match in $') -- Posted via http://www.ruby-forum.com/.