I am not sure exactly what you are asking, so I will offer multiple
suggestions and you can see what works best for you:
line.gsub!(/Bourgogne/,needle)
changes all occurrences
line.sub!(/Bourgogne/,needle)
changes the first occurrence (if any), as does
line[/Bourgogne/] = needle
or if you want to keep the original string you can write (note, no "!"):
new_line = line.sub(/Bourgogne/,needle)
or maybe you would rather:
rex = Regexp.new("^(.*)Bourgogne(.*)")
if line =~ rex
line = $1 + needle + $2
end
Hope this helps.
-- Markus
On Mon, 2004-10-04 at 23:39, Yvon Thoraval wrote:
> i have a regex like :
>
> rex = Regexp.new("^(.*)\s+Bourgogne[\\s*|\\s+(.*)]")
>
> but i want to change the string "Bourgogne" to the third arg of the
> script (needle = ARGV[2].to_s)
>
> what is the correct syntax in order to replace "Bourgogne" by that
> variable ?
>
> Also, i do have a test :
>
> if line =~ /^(.*)\s+Bourgogne\s*(.*)/
>
> using rex is the correct syntax :
>
> if line =~ rex
>
> ???
>