I need a function to return all the regular expression matches in a string and the positions at which matches are found (I want to highlight matches in a string).
There is a 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
ruby
Leonid Shevtsov
source share