I want to replace the last occurrence of a substring in Ruby. What\'s the easiest way? For example, in abc123abc123, I want to replace the last abc
simple and efficient:
s = "abc123abc123abc" p = "123" s.slice!(s.rindex(p), p.size) s == "abc123abcabc"