RegEx for matching all non-words except punctuation?
<p>For sentences like:</p>

<pre><code>sent = "This i$s a s[[]ample sentence.\nAnd another &lt;&lt;one&gt;&gt;.
        \nMoreover, it is 'filtered'!"
</code></pre>

<p>I would like to get:</p>

<pre><code>"This is a sample sentence. And another one. Moreover, it is filtered."
</code></pre>

<p>Thus, I thought using <code>re.sub</code> should be the way to go. However, RegEx doesn't work as expected (like it pretty much always does^^).</p>

<p>My idea was to use <code>\W</code> to match every non-word and then exclude <code>[.,;!?]</code> to keep the punctuation. The last RegEx I've tried was:</p>

<pre><code>re.sub(r"(\W[^\.\,\;\?\!])", "", sent)
</code></pre>

<p>Unfortunately, <code>[^\.\,\;\?\!]</code> does match for anything that does not contain an entry of<code>[.,;!?]</code>, instead of simply saying 'do <em>not</em> match these characters literally'.</p>

<p>How can I exclude these characters from match?</p>