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
Do you really need the position or is it enough to replace the matches on the fly?
s="I'mma let you finish but Beyonce had one of the best music videos of all time!" s.gsub(/(Beyonce|best)/, '\1')
=> "I'mma let you finish but Beyonce had one of the best music videos of all time!"