Message364052
Following on https://bugs.python.org/issue17087
Today I was mystified by why a regex wasn't working.
>>> import re
>>> re.match(r'.{10}', 'A'*49+'B')
<_sre.SRE_Match object; span=(0, 10), match='AAAAAAAAAA'>
>>> re.match(r'.{49}', 'A'*49+'B')
<_sre.SRE_Match object; span=(0, 49), match='AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA>
>>> re.match(r'.{50}', 'A'*49+'B')
<_sre.SRE_Match object; span=(0, 50), match='AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA>
I became confused on why the B wasn't matching in the third example; It is matching just
in the interactive debugger it doesn't fit on the line and doesn't show
My suggestion would be to truncate match (in the repr) and append '...' when it's right quote wouldn't show
with short matches (or exactly enough space) there would be no change
>>> re.match(r'.{48}', string.ascii_letters)
<_sre.SRE_Match object; span=(0, 48), match='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV'>
when not all of match can be displayed
>>> re.match(r'.{49}', string.ascii_letters)
<_sre.SRE_Match object; span=(0, 49), match='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW>
<_sre.SRE_Match object; span=(0, 49), match='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS'...>
I'm happy to help out by writing tests or impl if folks thing this is a good idea.
I couldn't think of other examples (urllib maybe?) in Python of how this is handled but I could potentially look for some if that would help |
|
Date |
User |
Action |
Args |
2020-03-12 21:49:27 | Seth.Troisi | set | recipients:
+ Seth.Troisi, serhiy.storchaka |
2020-03-12 21:49:27 | Seth.Troisi | set | messageid: <1584049767.16.0.188415292253.issue39949@roundup.psfhosted.org> |
2020-03-12 21:49:26 | Seth.Troisi | link | issue39949 messages |
2020-03-12 21:49:26 | Seth.Troisi | create | |
|