You could use [String#rindex](http://ruby-doc.org/core-2.0.0/String.html#method-i-rindex) to find the last occurrence rather than using a regular expression.  If there is a match, you could join the start of the string up to the index, the replacement string, and the end of the string from `index + string.size`.