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 <1224734129.35.0.170011642262.issue4185@psf.upfronthosting.co.za>
In-reply-to
Content
The re module seems to treat the raw strings as normal strings:
>>> 'a1a1a'.replace('1', r'\n') == re.sub('1', r'\n', 'a1a1a')
False
>>> 'a1a1a'.replace('1', '\n') == re.sub('1', r'\n', 'a1a1a')
True
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.

>>> re.search(r'\n', 'a\na')
<_sre.SRE_Match object at 0x00A81BF0>
>>> r'\n' in 'a\na'
False
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 http://bugs.python.org/msg71861 
Attached there is a txt file with more examples.
History
Date User Action Args
2008-10-23 03:55:29ezio.melottisetrecipients: + ezio.melotti
2008-10-23 03:55:29ezio.melottisetmessageid: <1224734129.35.0.170011642262.issue4185@psf.upfronthosting.co.za>
2008-10-23 03:55:28ezio.melottilinkissue4185 messages
2008-10-23 03:55:27ezio.melotticreate