title: Writing \r in Javascript string
body: <p>I want to write a script which adds in a string a backslash () everytime it finds a quotation marks or \r. It works but for " and ', but <strong>I don't know how to write it for \r.</strong> Could anyone help me? THANKS</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var test="Let\'s test if this \"works\" properly";
  var escapedString = test.replace(/(['"])/g, "\\$1");
  document.write(escapedString);
  &lt;/script&gt;
  </code></pre>
  
  <p>Output: Let\'s test if this \"works\" properly</p>