Author Seth.Troisi
Recipients Seth.Troisi, serhiy.storchaka
Date 2020-03-12.21:49:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1584049767.16.0.188415292253.issue39949@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2020-03-12 21:49:27Seth.Troisisetrecipients: + Seth.Troisi, serhiy.storchaka
2020-03-12 21:49:27Seth.Troisisetmessageid: <1584049767.16.0.188415292253.issue39949@roundup.psfhosted.org>
2020-03-12 21:49:26Seth.Troisilinkissue39949 messages
2020-03-12 21:49:26Seth.Troisicreate