Use raw string literals for regexes containing backlash.

This commit is contained in:
Georg Brandl 2010-07-12 09:06:13 +00:00
parent 4abda54889
commit db4e939206

View file

@ -1230,9 +1230,9 @@ in each word of a sentence except for the first and last characters::
... random.shuffle(inner_word) ... random.shuffle(inner_word)
... return m.group(1) + "".join(inner_word) + m.group(3) ... return m.group(1) + "".join(inner_word) + m.group(3)
>>> text = "Professor Abdolmalek, please report your absences promptly." >>> text = "Professor Abdolmalek, please report your absences promptly."
>>> re.sub("(\w)(\w+)(\w)", repl, text) >>> re.sub(r"(\w)(\w+)(\w)", repl, text)
'Poefsrosr Aealmlobdk, pslaee reorpt your abnseces plmrptoy.' 'Poefsrosr Aealmlobdk, pslaee reorpt your abnseces plmrptoy.'
>>> re.sub("(\w)(\w+)(\w)", repl, text) >>> re.sub(r"(\w)(\w+)(\w)", repl, text)
'Pofsroser Aodlambelk, plasee reoprt yuor asnebces potlmrpy.' 'Pofsroser Aodlambelk, plasee reoprt yuor asnebces potlmrpy.'