Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment: This is expected behavior and documented change in 3.7. The pattern ".*" can match an empty string, and it matches an empty string at the end of line. This behavior is consistent with the behavior of re.finditer() and with the behavior of all regular expression implementations in other programming languages. Actually it was an old bug in re.sub() that has been fixed in 3.7.
Compare, in 3.6: >>> list(re.finditer('.*', 'foo')) [<_sre.SRE_Match object; span=(0, 3), match='foo'>, <_sre.SRE_Match object; span=(3, 3), match=''>] >>> re.sub('.*', lambda m: repr(m), 'foo') "<_sre.SRE_Match object; span=(0, 3), match='foo'>" In 3.7: >>> list(re.finditer('.*', 'foo')) [<re.Match object; span=(0, 3), match='foo'>, <re.Match object; span=(3, 3), match=''>] >>> re.sub('.*', lambda m: repr(m), 'foo') "<re.Match object; span=(0, 3), match='foo'><re.Match object; span=(3, 3), match=''>" If you don't want to find an empty string, change you patter so that it will not match an empty string: ".+". ---------- resolution: -> not a bug stage: -> resolved status: open -> closed _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33585> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com