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'
|