J
John Wright
Say I want to replace all occurrences of \ in a string with \\:
test = "a string with \\ a backslash"
puts test.gsub(/\\/, "\\\\") #no worky
=> a string with \ a backslash
puts test.gsub(/\\/, "\\\\\\") #why does this work?
=> a string with \\ a backslash
Why does the replacement string have to be six backslashes? Hopefully
this is really simple and I'm just being dense...
test = "a string with \\ a backslash"
puts test.gsub(/\\/, "\\\\") #no worky
=> a string with \ a backslash
puts test.gsub(/\\/, "\\\\\\") #why does this work?
=> a string with \\ a backslash
Why does the replacement string have to be six backslashes? Hopefully
this is really simple and I'm just being dense...