I have a single, very long string that s output from a python function and need to split it onto multiple lines each time a \n is found.
I know I can use regex, but I'm not entirely sure how.
Any help would be much appreciated!
Thanks in advance.
I have a single, very long string that s output from a python function and need to split it onto multiple lines each time a \n is found.
I know I can use regex, but I'm not entirely sure how.
Any help would be much appreciated!
Thanks in advance.
I think, you don't have to use regex to solve your this task because it may work too slow for big strings. I would use io.StringIO
(or StringIO.StringIO
if you're using Python 2.7) to process your string:
from io import StringIO
s = "qwe\nrty\nuio"
s_stream = StringIO(s)
for line in s_stream:
print(line) # it prints data line by line
s_stream.close()