Possible re bug when using ".*"
MRAB
python at mrabarnett.plus.com
Wed Dec 28 14:07:06 EST 2022
On 2022-12-28 18:42, Alexander Richert - NOAA Affiliate via Python-list
wrote:
> In a couple recent versions of Python (including 3.8 and 3.10), the
> following code:
> import re
> print(re.sub(".*", "replacement", "pattern"))
> yields the output "replacementreplacement".
>
> This behavior does not occur in 3.6.
>
> Which behavior is the desired one? Perhaps relatedly, I noticed that even
> in 3.6, the code
> print(re.findall(".*","pattern"))
> yields ['pattern',''] which is not what I was expecting.
>
It's not a bug, it's a change in behaviour to bring it more into line
with other regex implementations in other languages.
More information about the Python-list
mailing list