From: Roel Harbers Date: 2007-04-27T15:14:12+09:00 Subject: Re: [patch] gsub with backslash characters in replacement string Adam Bozanich wrote: > Thanks, now I understand the problem. > > for the record, this still works after the patch: > > "abc".gsub(/(.)/,'\1,') # => "a,b,c," > > It is difficult (impossible?), however, to produce a \1 in the output > > irb(main):003:0> "abc".gsub(/(.)/,"\\\\1,") > => "\\\\1,\\\\1,\\\\1," > > and similarly a '\' before a register replacement. > > irb(main):016:0> "a".gsub(/(.)/,"\\\\\\1,") > => "\\\\a," > > I guess I just like having the "regex identity" property :) > > str = "\\" * 2 > str == str.gsub(str,str) # => true > > str = "a" > str == str.gsub(str,str) # => true > > Sorry for the false bug. > > -Adam It may not be a bug, although it's definitly unexpected, but shouldn't the documentation at least mention the double-escaping? Regards, Roel Harbers