Message317169
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: ".+". |
|
Date |
User |
Action |
Args |
2018-05-20 13:47:05 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, scop, ezio.melotti, mrabarnett |
2018-05-20 13:47:05 | serhiy.storchaka | set | messageid: <1526824025.09.0.682650639539.issue33585@psf.upfronthosting.co.za> |
2018-05-20 13:47:05 | serhiy.storchaka | link | issue33585 messages |
2018-05-20 13:47:05 | serhiy.storchaka | create | |
|