Greetings,

I'm trying to do something that should be very simple: stick a "\" in 
front of
every instance of "&" in a string.  However, the obvious code...

  "this&that".gsub!("&", "*")
  --> "this*that" # OK!

  "this&that".gsub!("&", "\\&")
  --> "this&that" # Wrong

...doesn't work, because "\&" means "last match" in gsub substitution 
strings.
How can I escape this?  I experimentally determined that entering 
"\\\\\\&"
(that's six backslashes) gets the desired result, but I don't really
understand why.  Is there a less obscure way of doing this?

Cheers,
-jani

-- 
Posted via http://www.ruby-forum.com/.