'test " test'.gsub('"', '\\"')# we got 'test \\\" test''test " test'.gsub('"', '"')# we got 'test \" test'