Suppose the string were
A.B.C blob3 45.6%. Text blob4.
Match all periods other than those both preceded and followed by a digit
If after replacements, the string
A B C blob3 45.6% Text blob4
were desired, one could use re.sub with the regular expression
r'(?<!\d)\.|\.(?!\d)'
to replace matches of periods with empty strings.
The regex reads, "match a period that is not preceded by a character other than a digit or is not followed by a character other than a digit".
Demo 1
The double-negative is employed to match a period at the beginning or end of the string. One could instead use the logical equivalent:
r'(?<=^|\D)\.|\.(?=\D|$)'
Match all periods except those both preceded and followed by a whitespace character
On the other hand, if, after substitutions, the string
A.B.C blob3 45.6% Text blob4
were desired one could use re.sub with the regular expression
r'(?<!\S)\.|\.(?!\S)'
to replace matches of periods with empty strings.
This regex reads, "match a period that is not preceded by a character other than a whitespace or is not followed by a character other than a whitespace".
Demo 2
One could instead use the logical equivalent:
r'(?<=^|\s)\.|\.(?=\s|$)'