From: "Wolfgang Nádasi-Donner" Date: 2009-03-07T21:00:34+09:00 Subject: [ruby-core:22719] Re: [Bug #1251] gsub problem Yukihiro Matsumoto schrieb: > To substitute one backslash into two, you have to do > > s.gsub!("\\","\\\\\\") ... myprompt> irb191-p0 irb(main):001:0> puts "a\\b".gsub!("\\","\\\\\\") a\\b => nil irb(main):002:0> puts "a\\b".gsub!("\\","\\\\\\\\") a\\b => nil I was surprized by this result long ago, until I started to assume, that the second replacement works only for \<...>, \nr, \\, and leaves the backslash as it is in all other combinations (even at end of the string). This ist different from the first replacement, which consumes always a backslash as escape character... myprompt> irb191-p0 irb(main):001:0> puts "\\\w" \w => nil I think this behaviour should be documented somewhere, because it can really confuse persons, which do not use complex RegExes during their daily work. Wolfgang N�dasi-Donner