title: Leave only alphanumeric symbols in string in Python?
body: <p>I am using Python 2.7.  On SO I found the following regexp for removing non-word characters:</p>
  
  <pre><code>pat = re.compile('[\W]+', re.UNICODE)
  </code></pre>
  
  <p>I wrote the next function:</p>
  
  <pre><code>def leave_only_alphanumeric(string):
    pat = re.compile('[\W]+', re.UNICODE)
    return re.sub(pat,' ',string)
  </code></pre>
  
  <p>Though on the following string:</p>
  
  <pre><code>kr\xc3\xa9m
  </code></pre>
  
  <p>it produces the wrong result:</p>
  
  <pre><code>kr\xc3 m 
  </code></pre>
  
  <p><code>\xa9</code> was deleted from the string, but should not have been.</p>