I want to escape a string such that all occurances of ‘&’ become ‘&’.
I can’t seem to do it with gsub.
irb(main):014:0> ‘&’.gsub(/&/, “&”)
"&“
irb(main):015:0> ‘&’.gsub(/&/, “\&”)
”&“
irb(main):016:0> ‘&’.gsub(/&/, “\&”)
”&“
irb(main):017:0> ‘&’.gsub(/&/, “\\&”)
”\&"
Have I stumbled upon a bug? It refuses to add a single backslash;
always zero or two.