A python script of mine started misbehaving in recent versions. I tracked it down to a re
substitution that behaves differently in python <=3.6 vs >= 3.7 Newer python versions make the substitution twice.
Did something break in python re
or am I doing something wrong and finally got caught?
As I understand it, the regex r'[^_]*$'
in the example code below should match everything after the last underscore ... or the whole string if there is no underscore.
In the following example, python 3.6 creates s == 'a_Z', whereas python 3.7 creates 'a_ZZ'
$ docker run --rm python:3.6-alpine python -c "import re;s=re.sub(r'[^_]*$','Z','a_b');assert s == 'a_Z',s"
$ docker run --rm python:3.7-alpine python -c "import re;s=re.sub(r'[^_]*$','Z','a_b');assert s == 'a_Z',s"
Traceback (most recent call last):
File "<string>", line 1, in <module>
AssertionError: a_ZZ
Same error with 3.8-alpine, 3.9-rc-buster.