re.sub() replaces all matches found, but using .* can cause the regex to match too much (even other occurrences of .00. , etc.). Just do:
In [2]: re.sub(r"\.(00|11)\.", r"X\1X", ".00..0..11.") Out[2]: 'X00X.0.X11X'
Please note that patterns cannot overlap:
In [3]: re.sub(r"\.(00|11)\.", r"X\1X", ".00.11.") Out[3]: 'X00X11.'
Tim pietzcker
source share