New submission from Anit Rajpurohit <anitrajpurohi...@gmail.com>:
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 <rep...@bugs.python.org> <https://bugs.python.org/issue41664> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com