use regular expressions to replace overlapping subpatterns,"re.sub('([a-zA-Z0-9])\\s+(?=[a-zA-Z0-9])', '\\1*', '3 /a 5! b')"