I would like to create a Ruby pattern to replace all but the last occurrence of a letter.
For example, replace all:
"}"
with the string:
"} something "
Turn this string:
"{ anything } { anything } { anything }"
to:
"{ anything } something { anything } something { anything }"
EDIT:
What I’ve used so far:
replaceString = "} something"
string.gsub("}", replaceString).reverse.sub(replaceString.reverse, "}").reverse
but I don’t think it is very effective.
You can use positive lookahead: