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.

classification
Title: re.sub() bug with IGNORECASE
Type: behavior Stage: resolved
Components: Regular Expressions Versions: Python 3.5, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Dan Wilt, ezio.melotti, mrabarnett, r.david.murray
Priority: normal Keywords:

Created on 2016-08-24 15:57 by Dan Wilt, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
re_bug.py Dan Wilt, 2016-08-24 15:57 MWE for re bug
Messages (3)
msg273575 - (view) Author: Dan Wilt (Dan Wilt) Date: 2016-08-24 15:57
Working with re.sub() noted strange behavior with re.I set, seems like a bug. Noted in both Python 2.7.12 and Python 3.5.2, Anaconda custom build (32-bit) on Windows 7.

>>> import re
>>> re.sub('\.', '', '.....')
''
>>> re.sub('\.', '', '.....', re.I)
'...'
>>> re.sub('\.', '', '.....', re.L)
'.'

The first case is the expected behavior, the second and third aren't. Oddly enough,

>>> re.sub('\.', '', '.....', re.L | re.I)
''

MWE file attached (python3)

Thanks, I'm a heavy python user, but not all that advanced - hope this is helpful and I'm not just being stupid.
msg273576 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-08-24 15:59
I really wish we could "fix" this somehow, since we get an issue opened for it probably every two or three months.

The fourth argument to re.sub is the count, not the flags.
msg273584 - (view) Author: Dan Wilt (Dan Wilt) Date: 2016-08-24 18:28
Thanks! That helps. I apologize for raising a non-existent issue.
Dan

On Wed, Aug 24, 2016 at 11:59 AM, R. David Murray <report@bugs.python.org>
wrote:

>
> R. David Murray added the comment:
>
> I really wish we could "fix" this somehow, since we get an issue opened
> for it probably every two or three months.
>
> The fourth argument to re.sub is the count, not the flags.
>
> ----------
> nosy: +r.david.murray
> resolution:  -> not a bug
> stage:  -> resolved
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue27851>
> _______________________________________
>
History
Date User Action Args
2022-04-11 14:58:35adminsetgithub: 72038
2016-08-24 18:28:02Dan Wiltsetmessages: + msg273584
2016-08-24 15:59:54r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg273576

resolution: not a bug
stage: resolved
2016-08-24 15:57:11Dan Wiltcreate