This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients ezio.melotti, gvanrossum
Date 2008-10-23.04:30:47
SpamBayes Score 3.52246e-12
Marked as misclassified No
Message-id <1224736259.43.0.369626656453.issue4185@psf.upfronthosting.co.za>
In-reply-to
Content
My bad, I only checked with help(re.sub).
In the examples with re.search I was indeed wrong because I forgot to
escape the \ and for the regex engine \n is the same of n (whereas \\n
is a literal \ followed by n), but I expected 'a1a1a'.replace('1',
r'\n') to return the same of re.sub('1', r'\n', 'a1a1a') because the
r'\n' is not a regex but a simple replacement string.
Also, the doc says "repl can be a string or a function; if it is a
string, any backslash escapes in it are processed. That is, \n is
converted to a single newline character, \r is converted to a linefeed,
and so forth.", this is the standard behavior of normal string, it
should be mentioned that the backslashes are processed even if with raw
strings and they need to be escaped with two \.
I think that changing the behavior of what is supposed to be a "normal
string" (the repl string) is not really a good idea (even if it's useful
when you have things like '\1\n' and assuming that this is why it has
different behavior), I'd rather prefer to use $1 instead of \1. Unlike
'\1', (as far as I know) $1 has no special meaning in Python so there
won't be any problem with raw strings.
History
Date User Action Args
2008-10-23 04:31:00ezio.melottisetrecipients: + ezio.melotti, gvanrossum
2008-10-23 04:30:59ezio.melottisetmessageid: <1224736259.43.0.369626656453.issue4185@psf.upfronthosting.co.za>
2008-10-23 04:30:57ezio.melottilinkissue4185 messages
2008-10-23 04:30:50ezio.melotticreate