title: How to remove all whitespaces except new lines with regex
body: <p>I wrote a code where I replaced all the whitespaces with new lines from a .txt file which is basically a novel. Doing this, seperated the words in new lines for me, but there are some empty lines and I want to remove those. So I am trying to remove all the whitespaces except the new lines. How might I do that using regex?</p>
  <p>First I did this to replace whitespaces with new lines:</p>
  <pre><code>text= re.sub(r'\s',r'\n',text)
  </code></pre>
  <p>Then I tried this to remove empty lines which is not doing the job actually:</p>
  <pre><code>text= re.sub(r'(\s)(^\n)',&quot;&quot;,text)
  </code></pre>