You need to run away \like this:
>>> import re
>>> x = 'the meaning\nof life'
>>> re.sub("([,\w])\n(\w)", "\1 \2", x)
'the meanin\x01 \x02f life'
>>> re.sub("([,\w])\n(\w)", "\\1 \\2", x)
'the meaning of life'
>>> re.sub("([,\w])\n(\w)", r"\1 \2", x)
'the meaning of life'
>>>
If you do not avoid this, the output will be \1, therefore:
>>> '\1'
'\x01'
>>>
To do this, we need to use '\\\\'or r'\\'to display the signal \in Python RegEx.
However, about this, from this answer :
, ( , "" , ).
:
, ('\'), . Python .
, RE, \section, LaTeX. , , , . , , \\section. , re.compile(), \\section. , Python, .
, brittenb, RegEx :
>>> x = 'the meaning\nof life'
>>> x.replace("\n", " ")
'the meaning of life'
>>>