I need a function to return all matches of a regexp in a string and positions at which the matches are found (I want to highlight matches in the string).
There is String#match that returns MatchData, but only for the first match.
Is there a better way to do this than something like
matches = []
begin
match = str.match(regexp)
break unless match
matches << match
str = str[match.end(0)..-1]
retry
end