How to clean a string using python regular expression
<p>I have the following string which have to clean</p>

<pre><code>#import re

addr="abcd&amp;^fhj"
problemchars = re.compile(r'[=\+/&amp;&lt;&gt;;\'"\?%#$@\,\. \t\r\n]')
re.search(problemchars,addr)
</code></pre>

<p>In that case use <code>re.sub</code> searching <code>\W</code> (non-alphanum) and replacing by nothing.</p>

<pre><code>import re

addr="abcd&amp;^fhj"
print(re.sub("\W","",addr))
</code></pre>

<p>(<code>"\W+"</code> works too, but not sure it would be more performant) </p>

python regex