Hi,

In message "Re: [ruby-core:23389] [Bug #1443] String#gsub handles backslashes incorrectly"
    on Thu, 7 May 2009 22:00:03 +0900, shawn landen <redmine / ruby-lang.org> writes:

|This is a continuation of bug #1441
|
|The backslashes are being doubled under single quotes and double quotes, but String#gsub requires you to quadruple (4x) them, 4 backslashes for every one in the resultant string.
|
|printf "b".gsub("b","\\\\")

Backslashes have special escape meaning in strings, so you need to
double slashes.  In addition, backslashes have special meaning in
gsub/sub replacement strings, so you need to double again.  That is
the reason you need 4 backslashes for each single backslash in a
replacement.  It's weird but it's spec for long time.  I don't think
we can change this behavior.  You can use block instead, e.g.

  printf "b".gsub(/b/){'\\'}

							matz.