I have a following string pattern in Python language for variable name msg:
from:\t[xxxxxx]\n
message:\tcontent_1\n
created_time:\tyyyyy\n
from:\t[xxxxxx]\n
message:\tcontent_2\n
created_time:\tyyyyy\n
from:\t[xxxxxx]\n
message:\tcontent_3\n
created_time:\tyyyyy\n
.
.
.
from:\t[xxxxxx]\n
message:\tcontent_n\n
created_time:\tyyyyy\n
What I am looking for matching is the content_1, content_2, content_3, ..., content_n To replace any "\n" inside any content_i with ","
For example of some content_i
sentence1\n sentence2\n sentence3
expected result as:
sentence1, sentence2, sentence3
but I found the problem when I try with
msg = re.sub(r"(\]\nmessage:.*?)\n", r"\1,", msg, re.M)
Some group of pattern, it also replace the \n between content_i and created_time with "," also but I don't want to replace it.
My question, I would like to use re module to searching \n in every content_i and replacing with "," only.
Note: any content_i can have many of \n inside