Suppose I have a string like this:
w="abc#name,xy.abc=abc"
I want to replace the first and the third "abc" with another string. I used this code:
puts w.gsub(/\babc\b/,"replacer");
# => replacer#name,xy.replacer=replacer
where the second "abc" is replaced, which was not what I expected. Then I changed to the following pattern:
puts w.gsub(/[^\.]\babc\b/,"replacer");
# => abc#name,xy.abcreplacer
where the first "abc" is not replaced. I have no idea now how to fix it.
You can try
but it’s a rather brute-force solution with negative look-behind.