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.

Author serhiy.storchaka
Recipients ezio.melotti, mrabarnett, scop, serhiy.storchaka
Date 2018-05-20.13:47:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1526824025.09.0.682650639539.issue33585@psf.upfronthosting.co.za>
In-reply-to
Content
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: ".+".
History
Date User Action Args
2018-05-20 13:47:05serhiy.storchakasetrecipients: + serhiy.storchaka, scop, ezio.melotti, mrabarnett
2018-05-20 13:47:05serhiy.storchakasetmessageid: <1526824025.09.0.682650639539.issue33585@psf.upfronthosting.co.za>
2018-05-20 13:47:05serhiy.storchakalinkissue33585 messages
2018-05-20 13:47:05serhiy.storchakacreate