Python regex : trimming special characters
<p>Is it possible to remove special characters using regex?</p>

<p>I'm attempting to trim:</p>

<pre><code>\n\t\t\t\t\t\t\t\t\t\tButte County High School\t\t\t\t\t\t\t\t\t
</code></pre>

<p>down to:</p>

<pre><code>Butte County High School
</code></pre>

<p>using    </p>

<pre><code>regexform = re.sub("[A-Z]+[a-z]+\s*",'', schoolstring)
print regexform
</code></pre>

<p>You do not need regex for this simple task. Use <a href="https://docs.python.org/2/library/string.html#string.lstrip" rel="nofollow"><code>string.strip()</code></a> instead. For example:</p>

<pre><code>&gt;&gt;&gt; my_string = '\t\t\t\t\t\t\t\t\t\tButte County High School\t\t\t\t\t\t\t\t\t'
&gt;&gt;&gt; my_string.strip()
'Butte County High School'
</code></pre>

<p>In case it is must to use <code>regex</code>, your expression should be:</p>

<pre><code>&gt;&gt;&gt; re.sub('[^A-Za-z0-9]\s+', '', my_string)
'Butte County High School'
</code></pre>

<p>It matches a string of characters that are not letters or numbers.</p>

python regex expression