I want to get the index as well as the results of a scan
\"abab\".scan(/a/)
I would like to have not only
=> [\"a\", \"a
Try this:
res = [] "abab".scan(/a/) do |c| res << [c, $~.offset(0)[0]] end res.inspect # => [["a", 0], ["a", 2]]