assume I have this string
text='bla1;\nbla2;\nbla3;\n#endif\nbla4;'
I want to define a method which removes all '\n' except if a '\n' is preceded by a string starting with '#' or '\n' follows '#', so the result of the process should be:
text2='bla1;bla2;bla3;\n#endif\nbla4;'
Is there a simple way to do this in python using regex?
(Note: is it clear to me how to avoid \n followed by #, using negative lookbehind, i.e. r'\n+(?!#)' but the challenge is how to identify a \n preceded by a string starting with #)
The challenge is: how to deal with a positive lookbehind with variable-length strings in python?