From: Kristof Bastiaensen Date: 2004-06-30T01:38:04+09:00 Subject: Re: String substitution bug On Tue, 29 Jun 2004 14:16:09 +0200, Martin Schoettler wrote: > (Ruby 1.8.1, Linux and Windows) > > puts "a\\b".sub( /\\/, "\\\\" ) > yields > a\b > (I expected: a\\b) > > But > puts "a\\b".sub( /\\/, "\\x\\" ) > yields > a\x\b > (as I would expect.) > > BTW: Mails to ruby-bugs@ruby-lang.org are rejected. Is there a new mail > adress for bugs? Hi, I don't know about bugs, but this however is not bug, but a feature :-) When using a replacement string, gsub does another elimination step for backslashes, because "\1" and "\2" have a special meaning. So first "\\\\" will be translated to "\\" for the quoted string, and the second time it will be translated to "\" by gsub. In the second case however gsub will see "\x\", and since "\x" doesn't have a special meaning it will be kept. Regards, Kristof