Robert Klemme wrote:
> 
> "Andreas Schwarz" <usenet / andreas-s.net> schrieb im Newsbeitrag
> news:slrnbht3o8.2jq.usenet / home.andreas-s.net...
>>
>> irb(main):001:0> "foo.bar".gsub '.', "*"
>> => "*******"
> 
> Ah, then it's a ruby version thingy.  I used 1.7.3.  Which one do you
> have?

ruby 1.6.8

>> irb(main):007:0> "foo.bar".gsub( /#{Regexp.escape(".")}/, "\\1")
>> => "foobar"
> 
> Why do you use \1 if you want to replace a fixed string?  Or do you want
> to insert \1?

Yes.

> Then you shoul've done
> 
> "foo.bar".gsub( /#{Regexp.escape(".")}/, Regexp.escape("\\1") )

irb(main):004:0> "foo.bar".gsub( /#{Regexp.escape(".")}/, Regexp.escape(".\\1") )
returns
  "foo\\.\\1bar"
instead of
  "foo.\\1bar"

Is there really no easy way to replace strings in Ruby?