Remove spaces before newlines
<p>I need to remove all spaces before the newline character throughout a string.</p>

<pre><code>string = """
this is a line       \n
this is another           \n
"""
</code></pre>

<p>output:</p>

<pre><code>string = """
this is a line\n
this is another\n
"""
</code></pre>

<p>As you can find <a href="http://stackoverflow.com/questions/8270092/python-remove-all-whitespace-in-a-string">here</a>, </p>

<p>To remove all whitespace characters (space, tab, newline, and so on) you can use split then join:</p>

<pre><code>sentence = ''.join(sentence.split())
</code></pre>

<p>or a regular expression:</p>

<pre><code>import re
pattern = re.compile(r'\s+')
sentence = re.sub(pattern, '', sentence)
</code></pre>

python