In[1]:importreIn[2]:re.sub('pattern',r'\\test','replace the pattern by \\test')Out[2]:'replace the \\test by \\test'In[3]:re.sub('pattern',r'\\lest','replace the pattern by \\lest')Out[3]:'replace the \\lest by \\lest'In[4]:re.sub('pattern',r'\\nest','replace the pattern by \\nest')Out[4]:'replace the \\nest by \\nest'
# raw string
Posté par GaMa (site web personnel) . En réponse au message Python, substitution et regex. Évalué à 2.
Il faut utiliser des raw strings
http://docs.python.org/reference/lexical_analysis.html#string-literals
Matthieu Gautier|irc:starmad