I have a ruby string which includes many escaped double quotes \" that I want to replace with an escaped single quote \' but I can't work out how to do it.
I've been trying to use gsub, but something like mystring.gsub('\\"', '\\'') doesn't work.
Sample of (part of) the string below - my problem is that I don't want to replace all the double quotes, just the escaped ones...
FYI, the injected script works fine in included as src, but I'm pulling the content dynamically and injecting into the script in the view:
instead of
<script src='...'></script>
Im doing
<script><%=raw @mystring%></script>
....
document.write("<div class=\"fsBody fsEmbed\">"+"\n");
document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"https://www.formstack.com/forms/css/3/reset.css?20140508\" />"+"\n");
document.write(" <link rel=\"stylesheet\" type=\"text/css\" href=\"https://www.formstack.com/forms/css/3/default.css?20140519\" />"+"\n");
document.write(" "+"\n");
document.write("<!--[if IE]>"+"\n");
document.write(" <link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"https://www.formstack.com/forms/css/3/ie.css?20140508\" />"+"\n");
document.write("<![endif]-->"+"\n");
document.write("<!--[if IE 7]><link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"https://www.formstack.com/forms/css/3/ie7.css\" /><![endif]-->"+"\n");
document.write("<!--[if IE 6]><link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"https://www.formstack.com/forms/css/3/ie6fixes.css\" /><![endif]-->"+"\n");
document.write(" <style type=\"text/css\">"+"\n");
document.write(" "+"\n");
document.write(" .fsBody .fsForm, .fsForm .fsSpacerRow .fsRowBody {"+"\n");
Can someone help?
"\"in certain circumstances, like when youinspecta variable or output it in irb.mystring.gsub('\\"', '\\\''). You first have to escape the slash, then escape the quote.` or"` when using single quotes. You only need to escape'or\` if proceeding'`.