This should be an easy question but I can\'t find anything about it.
Given a regular expression in Ruby, for every match I need to retrieve the matched patterns
You can access match data within scan like this:
"abcdefghij".scan(/\w/) {p $~}
MatchData
string.scan(regex) do $1 # Pattern at first position $2 # Pattern at second position $~.offset(1) # Starting and ending position of $1 $~.offset(2) # Starting and ending position of $2 end