From: Rodrigo Rosenfeld Rosas Date: 2012-03-06T23:03:21+09:00 Subject: [ruby-core:43095] Re: "\\".gsub("\\", "\\\\") == "\\" ?!!! Thanks for your explanation Xavier! Sorry for posting this in this list. Cheers, Rodrigo. Em 06-03-2012 10:54, Xavier Noria escreveu: > A literal passed as second argument to gsub goes over two > unescaping passes: the first one is the one as a string literal. The > second one is the one done by gsub itself since it has to detect > backreferences in the string object (note that a string object has no > escaping rules by itself, only literals have). > > So, \\\\ becomes \\ after the first pass, and that becomes \ after the > second pass. > > To get a double backslash you need to escape twice, one per pass. > > I normally use the block form of gsub to avoid so many backslashes. >