You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
re.sub() with re.MULTILINE not replacing all occurrences #59972
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2012-08-23.00:05:02.788>created_at=<Date2012-08-23.00:03:04.857>labels= ['expert-regex', 'type-bug', 'invalid']
title='re.sub() with re.MULTILINE not replacing all occurrences'updated_at=<Date2012-08-23.00:05:02.786>user='https://bugs.python.org/eacousineau'
[Copying post I made here: http://stackoverflow.com/questions/12082886/bug-in-python-regex-re-sub-with-re-multiline]
I'm noticing some odd behavior in Python's Regex library, and I'm not sure if I'm doing something wrong.
If I run a regex on it using re.sub(), with re.MULTILINE. It seems to only replace the first few occurrences. It replaces all occurrences if I turn off re.MULTILINE, use re.subn(..., count = 0, flags = re.MULTILINE), or compile the regex using re.compile(..., re.MULTILINE).
Activity
eacousineau commentedon Aug 23, 2012
[Copying post I made here: http://stackoverflow.com/questions/12082886/bug-in-python-regex-re-sub-with-re-multiline]
I'm noticing some odd behavior in Python's Regex library, and I'm not sure if I'm doing something wrong.
If I run a regex on it using re.sub(), with re.MULTILINE. It seems to only replace the first few occurrences. It replaces all occurrences if I turn off re.MULTILINE, use re.subn(..., count = 0, flags = re.MULTILINE), or compile the regex using re.compile(..., re.MULTILINE).
I am running Python 2.7 on Ubuntu 12.04.
I've posted a random example on:
http://pastebin.com/49SU8Mm2 - Output from terminal
http://codepad.org/2RO2iS4O - Script, confirming behavior (except for re.subn(), which is different on 2.5)
eacousineau commentedon Aug 23, 2012
Looks like I was just writing my code incorrectly - I should have been using re.sub(..., flags = re.MULTILINE).
That explains it.