Python Text Cleaning Remove spaces between non alpha numeric characters
<p>I have a text-file with alphanumeric and non-alphanumeric characters in the text.</p>

<p>I want to remove any spaces that are between two non-alphanumeric characters.</p>

<p>How can I achieve this efficiently?</p>

<p>Any method/popular libraries is fine.</p>

<p>Here's a possible solution to your question:</p>

<pre><code>import re

file = """
    7     u         p, S   a k    s F i f t h A v e, A u d i A     4, C a n o n A 7 5
"""

print re.sub(r"([A-Za-z0-9])\ *([A-Za-z0-9])\ *", r"\1\2", file)
</code></pre>

<p>I think <a href="https://docs.python.org/2/library/re.html#re.sub" rel="nofollow">re.sub</a> is a good way to go here.</p>

python parsing text