Brian Candler wrote in post #991406:
> 7stud -- wrote in post #991338:
>> You can also get relative beginning offsets 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
>>
>> end
>
> Using 'index' doesn't work if you have multiple captures which have the
> same pattern, or one is a substring of the other.
>
> Use captures.begin and captures.end instead.
>

begin() and end() are the two elements of offset(), which we've already 
discussed above:

 The idea was to get the relative offsets within a match, not the 
absolute offsets within the string.

-- 
Posted via http://www.ruby-forum.com/.