Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment: Good point. Neither old nor new (which matches regex) behaviors conform the documentation: "Empty matches are included in the result unless they touch the beginning of another match." It is easy to exclude empty matches that touch the *ending* of another match. This would be consistent with the new behavior of split() and sub().
But this would break a one existing test for issue817234. Though that issue shouldn't rely on this detail. The test should just test that iterating doesn't hang. And this would break a regular expression in pprint. PR 4678 implements this version. I don't know what version is better. >>> list(re.finditer(r"\b|:+", "a::bc")) [<re.Match object; span=(0, 0), match=''>, <re.Match object; span=(1, 1), match=''>, <re.Match object; span=(1, 3), match='::'>, <re.Match object; span=(5, 5), match=''>] >>> re.sub(r"(\b|:+)", r"[\1]", "a::bc") '[]a[][::]bc[]' With PR 4471 the result of re.sub() is the same, but the result of re.finditer() is as in msg307424. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue25054> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com