title: Ruby backreference in gsub is not working properly
body: <p>I am confused with the following result, </p>
  
  <p>I have a string like this:-</p>
  
  <pre><code>string = "hai\"hello\!tst\`\~end"
  </code></pre>
  
  <p>When I use space between backslash and back-reference (\1) it is working fine as expected.</p>
  
  <pre><code>puts string.gsub(/([\"\!\`\~])/,'\\ \1')
  =&gt; hai\ "hello\ !tst\ `\ ~end
  </code></pre>
  
  <p>But the same thing is not working without space! The string is replaced with the backreference number.</p>
  
  <pre><code>puts string.gsub(/([\"\!\`\~])/,'\\\1')
  =&gt; hai\1hello\1tst\1\1end
  </code></pre>
  
  <p>But I am expecting answer like</p>
  
  <pre><code>=&gt; hai\"hello\!tst\`\~end
  </code></pre>
  
  <p>Let me know if you need more information. Thanks in advance.</p>