http: // aaa / ccc →
http: // aaa / bbb / ccc
--However, you can leave the
http: // aaa / bbb / ccc as it is.
I wanted a command that could be used in that situation. In other words, it is an exclusion that there are patterns that replace, but exclude everything instead of replacing it.
Use regular expression negative look-ahead
For example, if you don't replace only the past system of play,
"play plays played".gsub(/play(?!ed)/, "eat") #=> "eat eats played"
It becomes the command. Regarding the above url,
"http://aaa/ccc".gsub(/http:\/\/aaa\/(?!bbb\/)/, "http://aaa/bbb/") #=>"http://aaa/bbb/ccc" "http://aaa/bbb/ccc".gsub(/http:\/\/aaa\/(?!bbb\/)/, "http://aaa/bbb/") # => "http://aaa/bbb/ccc"