In response to Michael's post , about a nasty regex...
Yesterday I fooled around with lookbehinds and lookaheads and what not. Very weird stuff :)
If I've understood the problem correctly I think the solution could be:
>>>import re
>>>s='test\ntest2\ntest3\r\n\n\ntest4\r\ntest5\n\n\n\n'
>>>r= '(?<!\r)\n'
>>>re.sub(r,'\r\n',s)
'test\r\ntest2\r\ntest3\r\n\r\n\r\ntest4\r\ntest5\r\n\r\n\r\n\r\n'
Comments
Comment by Orestis Markou , 4 years, 3 months ago :
Heh, I just learned about lookbehinds yesterday! Glad to be of service, even from away :)
Very weird to get at first, but once they click they seem very simple. I tried around 10 times to get it right. I *will* be frightened if I see them somewhere else, though, as with all regexes :) Thankfully, the above is very simple.
This post is older than 30 days and comments have been turned off.

Comment by xtian , 4 years, 3 months ago :
Thanks Orestis - that works well, and is heaps nice than my abomination! I knew I should have looked back at the regex syntax page.