On Python 3.7 (tested on Windows 64 bits), the replacement of a string using the RegEx .* gives the input string repeated twice!
On Python 3.7.2:
>>> import re
>>> re.sub(".*", "(replacement)", "sample text")
'(replacement)(replacement)'
On Python 3.6.4:
>>> import re
>>> re.sub(".*", "(replacement)", "sample text")
'(replacement)'
On Python 2.7.5 (32 bits):
>>> import re
>>> re.sub(".*", "(replacement)", "sample text")
'(replacement)'
What is wrong? How to fix that?
.*(or.*$), not with.+or^.*. And, well, you have an infinite number of zero-byte strings at the end of your match, so you might as well be glad that you get only one repetition. :) - Charles Duffy.*is greedy, I expect to get '(replacement)' only once. Why two? - Laurent LAPORTE3.7.2also... oddly enough if you had nothing in there, the replacement only happens once. I'm guessing beginning of string^and end of string$counts as two empty space characters? - r.ook