Is this the template you mean?
In [15]: s = 'some text with \tspaces between' In [16]: timeit re.sub(r'(\w)(\s+)(\w)', '\\1 \\3', s) 10000 loops, best of 3: 30.5 us per loop In [17]: timeit re.sub(r'(\w)(\s+?)(\w)', '\\1 \\3', s) 10000 loops, best of 3: 24.9 us per loop
There seems to be a pretty slight difference. Only 5 microseconds with inanimate
Using 500 words of lorem-ipsum, with a few mixed spaces between each word, I get a difference of 8 ms.
source share