I am using Python 3.5, and I would like to split a string by the character
a = '''red
['red', 'yellow', 'green\n_surprise', 'blue']
It's pretty easy using regular expressions:
import re re.split('\n(?!_)', a) # ['red', 'yellow', 'green\n_surprise!', 'blue']
This regex litterally means
split by \n not followed by _.