title: Python regex to replace double backslash with single backslash
body: <p>I'm trying to replace all double backslashes with just a single backslash. I want to replace <code>'class=\\"highlight'</code> with <code>'class=\"highlight'</code>. I thought that python treats <code>'\\'</code> as one backslash and <code>r'\\+'</code> as a string with two backslashes. But when I try</p>
  
  <pre><code>In [5]: re.sub(r'\\+', '\\', string)
  sre_constants.error: bogus escape (end of line)
  </code></pre>
  
  <p>So I tried switching the replace string with a raw string:</p>
  
  <pre><code>In [6]: re.sub(r'\\+', r'\\', string)
  Out [6]: 'class=\\"highlight'
  </code></pre>
  
  <p>Which isn't what I need. So I tried only one backslash in the raw string:</p>
  
  <pre><code>In [7]: re.sub(r'\\+', r'\', string)
  SyntaxError: EOL while scanning string literal    
  </code></pre>