Mailing List Archive

[issue40027] re.sub inconsistency beginning with 3.7
Brian <python-bugs@brisammon.fastmail.fm> 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 <report@bugs.python.org>
<https://bugs.python.org/issue40027>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue40027] re.sub inconsistency beginning with 3.7 [ In reply to ]
Brian <python-bugs@brisammon.fastmail.fm> 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 <report@bugs.python.org>
<https://bugs.python.org/issue40027>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com