title: Replace single quote with backslash single quote in python
body: <p>I have been trying to replace a single quote with back slash single quote.</p>
  
  <p>I have been trying this but it results in a string with two backslashes and single quote or without any backslash and single quote.</p>
  
  <pre><code>re.sub("'","\'","Newton's method")
  </code></pre>
  
  <p>The above results in O/P : <code>Newton's method</code></p>
  
  <p>While <code>re.sub("'","\\'","Newton's method")</code> results in <code>Newton\\'s method</code></p>
  
  <p>I need <code>Newton\'s method</code> as the output.</p>
  
  <p>Any help is appreciated.</p>
  
  <p><strong>Update :</strong>  </p>
  
  <p>This is a string which is created after parsing and is passed using an html form. Here <code>"Newton's method"</code> causes a problem since it deforms the json after the get request.</p>
  
  <pre><code>{'1': u'Newton metre', '0': u'Newton', '3': u'Newton (unit)', '2': u'Newton Centre, Massachusetts', '5': u'NewtonCotes formulas', '4': u'.30 Newton', '7': u'Newton Highlands, Massachusetts', '6': u"Newton's method", '9': u'List of things named after Isaac Newton', '8': u'Bill Newton'}
  </code></pre>
  
  <p>The html form gets this by a get request while the back end fetches it incorrectly.</p>
  
  <pre><code> {'1': u'Newton metre', '0': u'Newton', '3': u'Newton (unit)', '2': u'Newton Centre, Massachusetts', '5': u'NewtonCotes formulas', '4': u'.30 Newton', '7': u'Newton Highlands, Massachusetts', '6': u
  </code></pre>