Alexander Pettelkau schrieb: > Bug #1251: gsub problem > http://redmine.ruby-lang.org/issues/show/1251 > > Author: Alexander Pettelkau > Status: Open, Priority: Normal > Category: core, Target version: 1.9.1 > ruby -v: ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-darwin9.6.0] > > I wanted to replace "\" with "\\" in the string "\TEST": > > s="\\TEST" > puts s # Output --> "\TEST" > s.gsub!("\\","\\\\") > puts s # Output --> "\TEST" > # but EXPECTED Output "\\TEST" > > > ---------------------------------------- > http://redmine.ruby-lang.org > > After the first step, the String contains two backslashes. This string will be interpreted again, because there can be references to matched groups inside (e.g. '\1'). This second interpretation sees a escaped backslash (backslash-backslash, which results in one backslash. I think it should be documented, Wolfgang NĂ¡dasi-Donner