Replacing text except in the url

Say that we have the following text

abc def

I know how to replace “abc” by some text for instance. But, when I do
that, how can I tell the program NOT to substitute the “abc” in the url?


Well, in that example…

You could replace only the first occurrence:

s.sub /abc/, ‘xyz’

Or only at the start of the line:

s.gsub /^abc/, ‘xyz’

Or specifically omit anything starting with “http://”

s.gsub /(?<!http://)abc/, ‘xyz’