[issue41664] re.sub does NOT substitute all the matching patterns when re.IGNORECASE is used

2020-08-29 Thread Matthew Barnett


Matthew Barnett  added the comment:

The 4th argument of re.sub is 'count', not 'flags'.

re.IGNORECASE has the numeric value of 2, so:

re.sub(r'[aeiou]', '#', 'all is fair in love and war', re.IGNORECASE)

is equivalent to:

re.sub(r'[aeiou]', '#', 'all is fair in love and war', count=2)

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41664] re.sub does NOT substitute all the matching patterns when re.IGNORECASE is used

2020-08-29 Thread Anit Rajpurohit


New submission from Anit Rajpurohit :

Usage of re flags leads to inconsistent results when 
1. The pattern directly used in re.sub
2. The pattern is re.compile'd and used 

Note 1: Input string is all in the lowercase 'all is fair in love and war'
Note 2: Results are always consistent in case of re.compile'd pattern
===
1. The pattern directly used in re.sub
===
>>> import re
>>> re.sub(r'[aeiou]', '#', 'all is fair in love and war')
'#ll #s f##r #n l#v# #nd w#r'
>>> 
>>> re.sub(r'[aeiou]', '#', 'all is fair in love and war', re.IGNORECASE)
'#ll #s fair in love and war'
>>> 
>>> re.sub(r'[aeiou]', '#', 'all is fair in love and war', 
>>> re.IGNORECASE|re.DOTALL)
'#ll #s f##r #n l#v# #nd w#r'
>>> 
>>> 
===
2. The pattern is re.compile'd and used 
===
>>> pattern = re.compile(r'[aeiou]', re.IGNORECASE)
>>> re.sub(pattern, '#', 'all is fair in love and war')
'#ll #s f##r #n l#v# #nd w#r'
>>> 
>>> pattern = re.compile(r'[aeiou]')
>>> re.sub(pattern, '#', 'all is fair in love and war')
'#ll #s f##r #n l#v# #nd w#r'
>>> 
>>> pattern = re.compile(r'[aeiou]', re.IGNORECASE | re.DOTALL)
>>> re.sub(pattern, '#', 'all is fair in love and war')
'#ll #s f##r #n l#v# #nd w#r'

--
components: Regular Expressions
messages: 376083
nosy: anitrajpurohit28, ezio.melotti, mrabarnett
priority: normal
severity: normal
status: open
title: re.sub does NOT substitute all the matching patterns when re.IGNORECASE 
is used
type: behavior
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com