New submission from Seth Troisi <brain...@gmail.com>:
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 ---------- components: Library (Lib) messages: 364052 nosy: Seth.Troisi, serhiy.storchaka priority: normal severity: normal status: open title: truncating match in regular expression match objects repr type: enhancement _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39949> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com