I’m having some problem replacing a partial of a string with another string.
I want this string "this-is-a-string.jpg" to be replaced with "this-is-a-hash.jpg".
The string value can be any value.
This is what I’ve so far.
str = "this-is-a-string.jpg"
str.gsub(/([a-z]+)[^\.]+?$/i, "hash")
# => "this-is-a-string.hash"
I played around with rubular and I came up with a regexp which works if you don’t mind adding a dot manually to the replacement.
Here is what I came up with
So I guess you could make a simple function which replaces it like
in ruby 1.9.2 I managed to extract the word “string” but I don’t know if that is of any use to you.
I hope I’ve helped you and given the information you needed