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
Date 2008-10-23.03:55:27
SpamBayes Score 8.20872e-06
Marked as misclassified No
Message-id <>
The re module seems to treat the raw strings as normal strings:
>>> 'a1a1a'.replace('1', r'\n') == re.sub('1', r'\n', 'a1a1a')
>>> 'a1a1a'.replace('1', '\n') == re.sub('1', r'\n', 'a1a1a')
In the first line str.replace and re.sub should perform exactly the same
operation and return the same result but re.sub replaces the 1s with
newlines, instead of a literal '\' and 'n'.
The second line should evaluate to False but re.sub replaces again the
1s with newlines so the result is equal to the LHS.

>>>'\n', 'a\na')
<_sre.SRE_Match object at 0x00A81BF0>
>>> r'\n' in 'a\na'
Searching a r'\n' in a string that contains a newline also return a
result even if r'\n' is not in 'a\na'.

Tested with Py2.5 on Linux and Py2.4/2.6 on win.
The problem could be related to 
Attached there is a txt file with more examples.
Date User Action Args
2008-10-23 03:55:29ezio.melottisetrecipients: + ezio.melotti
2008-10-23 03:55:29ezio.melottisetmessageid: <>
2008-10-23 03:55:28ezio.melottilinkissue4185 messages
2008-10-23 03:55:27ezio.melotticreate