Raw string substitution problem

Sion Arrowsmith sion at viridian.paintbox
Fri Dec 18 12:09:41 EST 2009


Gregory Ewing  <greg.ewing at canterbury.ac.nz> wrote:
>MRAB wrote:
>> Regular expressions and replacement strings have their own escaping
>> mechanism, which also uses backslashes.
>This seems like a misfeature to me. It makes sense for
>a regular expression to give special meanings to backslash
>sequences, because it's a sublanguage with its own syntax.
>But I can't see any earthly reason to do that with the
>*replacement* string, which is just data.

>>> re.sub('a(.)c', r'\1', "123abcdefg")
'123bdefg'

Still think the replacement string is "just data"?

-- 
\S

   under construction




More information about the Python-list mailing list