I want to replace \n in front of any digit in mystring, while keeping the digit the same as before. I tried the following.
mystring = "\n this \n 1. is \n 2. some \n 3. text \n"
k = re.sub('\n \d', '\d', mystring)
k
I do not want to replace all "\n". Only the ones in front digits. However in my output, the digits are replaced with "\d" and I want to know how to keep them the same.
My output:
'\n this \\d. is \\d. some \\d. text \n'
expected output
'\n this 1. is 2. some 3. text \n'