Issue 24071: Python 2.7.8, 2.7.9 re.MULTILINE failure (original) (raw)

Issue24071

Created on 2015-04-28 19:25 by Stephen.Evans, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
refail.py Stephen.Evans,2015-04-28 19:25 re.MULTILINE failure example
Messages (4)
msg242205 - (view) Author: Stephen Evans (Stephen.Evans) Date: 2015-04-28 19:25
A simple multiline regex fails when just the re.MULTILINE argument is used, but works when equivalent alternative methods are used. This was tested on Python2.7.8 on FreeBSD and Win32 Python2.7.9 data = re.sub(r'#.*', '', text, re.MULTILINE) # fails data = re.sub(r'(?m)#.*', '', text) # Ok data = re.sub(r'#.*', '', text, re.MULTILINE|re.DEBUG) # Ok All the expressions work correctly with Win64 Python3.4.3 The attached file has the code and with a sample of text that fails.
msg242206 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2015-04-28 19:38
The 4th argument of re.sub is the maximum count (0 means unlimited). >>> help(re.sub) Help on function sub in module re: sub(pattern, repl, string, count=0, flags=0) Return the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in string by the replacement repl. repl can be either a string or a callable; if a string, backslash escapes in it are processed. If it is a callable, it's passed the match object and must return a replacement string to be used. The value of re.MULTILINE is 8: >>> re.MULTILINE 8 therefore it'll perform a maximum of 8 substitutions. In summary: not a bug.
msg242363 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-05-02 01:20
It is, however, frequently reported as a bug, if that makes you feel any better :)
msg257140 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2015-12-28 22:21
See #11957.
History
Date User Action Args
2022-04-11 14:58:16 admin set github: 68259
2015-12-28 22:21:48 ezio.melotti set messages: +
2015-05-02 01:20:27 r.david.murray set nosy: + r.david.murraymessages: +
2015-04-28 20:04:13 serhiy.storchaka set status: open -> closedresolution: not a bugstage: resolved
2015-04-28 19:38:44 mrabarnett set messages: +
2015-04-28 19:25:28 Stephen.Evans create