Suppose I have this:
import re
s = ' Hello, world '
re.sub(r'\S+', 'a', s)
it gets me
' a a '
as expected (greedily taking longest substring with at least one \S (any unicode non-whitespace) character, but
re.sub(r'\S*', 'a', s)
gets me
'a a a a a a a a a a a a'
which seems weird to me. Where did all those whitespace substrings go? What is really going on here?
E: I understand that it puts string 'a' every time it matches an empty string, but I can't follow why it doesn't leave whitespace substrings alone, as \S* shouldn't be a match for them, as opposed to \s*