[issue40027] re.sub inconsistency beginning with 3.7

2021-09-22 Thread Brian
Brian added the comment: txt = ' test' txt = re.sub(r'^\s*', '^', txt) substitutes once because the * is greedy. txt = ' test' txt = re.sub(r'^\s*?', '^', txt) substitutes twice, consistent with the \Z behavior. -- ___ Python tracker

[issue40027] re.sub inconsistency beginning with 3.7

2021-09-22 Thread Brian
Brian added the comment: I just ran into this change in behavior myself. It's worth noting that the new behavior appears to match perl's behavior: # perl -e 'print(("he" =~ s/e*\Z/ah/rg), "\n")' hahah -- nosy: +bsammon ___ Python tracker

[issue40027] re.sub inconsistency beginning with 3.7

2020-08-08 Thread Wayne Davison
Wayne Davison <4way...@gmail.com> added the comment: Can this bug please be reopened and fixed? This is an anchored substitution, and so should never match more than once. -- nosy: +4wayned ___ Python tracker __

[issue40027] re.sub inconsistency beginning with 3.7

2020-03-20 Thread Wayne Davison
Wayne Davison added the comment: Another argument in favor of this being a bug, this does not exhibit the same doubling: txt = ' test' txt = re.sub(r'^\s*', '^', txt) That always substitutes once. -- ___ Python tracker

[issue40027] re.sub inconsistency beginning with 3.7

2020-03-20 Thread Wayne Davison
Wayne Davison added the comment: This is not the same thing because the match is anchored, so it is not adjacent to the prior match -- it is the same match. I think that r'\s*\Z' should behave the same way as r'\s*x' due to the anchor point. The current behavior is matching the same \Z twice

[issue40027] re.sub inconsistency beginning with 3.7

2020-03-20 Thread Matthew Barnett
Matthew Barnett added the comment: Duplicate of Issue39687. See https://docs.python.org/3/library/re.html#re.sub and https://docs.python.org/3/whatsnew/3.7.html#changes-in-the-python-api. -- resolution: -> duplicate stage: -> resolved status: open -> closed ___

[issue40027] re.sub inconsistency beginning with 3.7

2020-03-20 Thread Wayne Davison
New submission from Wayne Davison : There is an inconsistency in re.sub() when substituting at the end of a string using a prior match with a '*' qualifier: the substitution now occurs twice. For example: txt = re.sub(r'\s*\Z', "\n", txt) This should work like txt.rstrip() + "\n", but begin