I want to replace all occurrences of a single quote ('
) with backslash single quote (\'
). I tried doing this with gsub
, but I'm getting partial string duplication:
a = "abc 'def' ghi"
a.gsub("'", "\\'")
# => "abc def' ghidef ghi ghi"
Can someone explain why this happens and what a solution to this is?