title: Delete substring when it occurs once, but not when twice in a row in python
body: <p>I know how to delete or replace a substring. But I want it only under the condition that the substring occurs non-repetive. I have made a workaround which looks very ugly and I want to know if there is a better solution.</p>
  
  <p>Assuming the following string:</p>
  
  <pre><code>test = "Hello\n,I am here now.\n\nSo what's the problem?"  
  </code></pre>
  
  <p>The first <code>"\n"</code> should be deletet, however the second <code>"\n\n"</code> should not. </p>
  
  <p>To do so I I replace the <code>"\n\n"</code> with something that would never be in a normal conversational string, like:</p>
  
  <pre><code>x = test.replace('\n\n','42#*#')
  x = x.replace('\n','')
  x = x.replace('42#*#','\n\n')
  </code></pre>
  
  <p>Which works, but I want to know if there would be a nicer solution to this problem?</p>
  
  <p><strong>edit</strong>: I tried the solution from <a href="https://stackoverflow.com/questions/22547113/split-a-string-on-a-certain-character-only-if-it-doesnt-follow-directly-after-a">Split a string on a certain character only if it doesn&#39;t follow directly after another particular character</a></p>
  
  <p>However, when using the following regular expression:</p>
  
  <pre><code>re.split('(?&lt;!,)\n', test)
  </code></pre>
  
  <p>I will get the following result:</p>
  
  <pre><code>['Hello', ',I am here now.', '', "So what's the problem?"]
  </code></pre>
  
  <p>So both <code>\n</code> and <code>\n\n</code> were deleted, how can I avoid this?</p>