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
Here's another possible solution:
>> s = "abc123abc123" => "abc123abc123" >> s[s.rindex('abc')...(s.rindex('abc') + 'abc'.length)] = "ABC" => "ABC" >> s => "abc123ABC123"