title: Reversing Python's re.escape
body: <p>How to reverse re.escape? <a href="https://mentaljetsam.wordpress.com/2007/04/13/unescape-a-python-escaped-string/" rel="noreferrer">This blog from 2007</a> says there is no reverse function, but is that still true, ten years later?</p>
  
  <p>Python 2's <code>decode('string_escape')</code> doesn't work on all escaped chars (such as space).</p>
  
  <pre><code>&gt;&gt;&gt; re.escape(' ')
  '\\ '
  &gt;&gt;&gt; re.escape(' ').decode('string-escape')
  '\\ '
  </code></pre>
  
  <p>Python 3: <a href="https://stackoverflow.com/questions/14820429/how-do-i-decodestring-escape-in-python3">Some suggest</a> <code>unicode_escape</code> or <code>codec.escape_decode</code> or <code>ast.literal_eval</code> but no luck with spaces.</p>
  
  <pre><code>&gt;&gt;&gt; re.escape(b' ')
  b'\\ '
  &gt;&gt;&gt; re.escape(b' ').decode('unicode_escape')
  '\\ '
  &gt;&gt;&gt; codecs.escape_decode(re.escape(b' '))
  (b'\\ ', 2)
  &gt;&gt;&gt; ast.literal_eval(re.escape(b' '))
  ValueError: malformed node or string: b'\\ '
  </code></pre>
  
  <p>So is this really the only thing that works?</p>
  
  <pre><code>&gt;&gt;&gt; re.sub(r'\\(.)', r'\1', re.escape(' '))
  ' '
  </code></pre>