Say that we have the following text
abc def http://abc.net
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?
Thanks.
Say that we have the following text
abc def http://abc.net
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?
Thanks.
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’
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs