re.sub() (docs for Python 2 and Python 3) does replace all matches it finds, but your use of .* may have caused the regex to match too much (even other occurences of .00. etc.). Simply do:

In [2]: re.sub(r"\.(00|11)\.", r"X\1X", ".00..0..11.")
Out[2]: 'X00X.0.X11X'

Note that patterns cannot overlap:

In [3]: re.sub(r"\.(00|11)\.", r"X\1X", ".00.11.")
Out[3]: 'X00X11.'
Answer from Tim Pietzcker on Stack Overflow
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ re.html
re โ€” Regular expression operations โ€” Python 3.14.3 ...
sub() replaces every occurrence of a pattern with a string or the result of a function. This example demonstrates using sub() with a function to โ€œmungeโ€ text, or randomize the order of all the characters in each word of a sentence except ...
๐ŸŒ
PYnative
pynative.com โ€บ home โ€บ python โ€บ regex โ€บ python regex replace pattern in a string using re.sub()
Python Regex Replace and Replace All โ€“ re.sub()
July 19, 2021 - Letโ€™s assume you have the following string and you wanted to replace all the whitespace with an underscore. target_string = "Jessa knows testing and machine learning" ... import re target_str = "Jessa knows testing and machine learning" res_str = re.sub(r"\s", "_", target_str) # String after replacement print(res_str) # Output 'Jessa_knows_testing_and_machine_learning'Code language: Python (python) Run
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python regex replace all
Python regex replace all - Spark By {Examples}
May 31, 2024 - One of the most used methods in the Python re library is the re.sub() which is used to replace a new string for all instances of a pattern in a string (Python regex replaces all).
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Replace Strings in Python: replace(), translate(), and Regex | note.nkmk.me
May 4, 2025 - If you need to replace substrings based on regex patterns, use the sub() or subn() functions from the re module. re.sub() โ€” Regular expression operations โ€” Python 3.13.3 documentation
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ what-is-the-resub-function-in-python
What is the re.sub() function in Python?
The re module provides users with ... the re module functions. It is a substitution function that replaces all occurrences of the specified pattern with a new string....
๐ŸŒ
LZone
lzone.de โ€บ examples โ€บ Python re.sub
Python re.sub Examples
result = re.sub('abc', '', input) # Delete pattern abc result = re.sub('abc', 'def', input) # Replace pattern abc -> def result = re.sub(r'\s+', ' ', input) # Eliminate duplicate whitespaces using wildcards result = re.sub('abc(def)ghi', r'\1', input) # Replace a string with a part of itself
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ re-sub-python-regex
re.sub() - Python RegEx - GeeksforGeeks
July 23, 2025 - re.sub() method in Python parts of a string that match a given regular expression pattern with a new substring. This method provides a powerful way to modify strings by replacing specific patterns, which is useful in many real-life tasks like text processing or data cleaning. ... import re a = "apple orange apple banana" pattern = "apple" repl = "grape" # Replace all occurrences of "apple" with "grape" result = re.sub(pattern, repl, a) print(result)
Find elsewhere
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Replacement argument in re.sub() - Python Help - Discussions on Python.org
November 10, 2022 - Hello, I have the following strings that I would like to match and replace. I am able to match the strings but struggling to carry out a replacement - the output either doesnโ€™t change or it completely erases sections of the input string. i have included an example of one of many options I have tried. scenario 1: input string: (BXXADDB)(BXXXCAC1)(CXX2A)CANEVER desired output string: (BXXADDB)(BXXXCAC1)(CXX2A)*CANEVER pattern = r"^\([A-Za-z0-9]+\)\([A-Za-z0-9]+\)\([^)]*\)[a-zA-Z]+$" replaceme...
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ regular expressions โ€บ re.sub()
Python | Regular Expressions | re.sub() | Codecademy
October 14, 2024 - The re.sub() function replaces matching substrings with a new string for all occurrences, or a specified number. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
๐ŸŒ
Medium
medium.com โ€บ @wepypixel โ€บ complete-python-regex-replace-guide-using-re-sub-pypixel-9b30b2604d7a
Complete Python Regex Replace Guide using re.sub() | PyPixel | by Stilest | Medium
December 8, 2023 - The re.sub() method in Python provides powerful search and replace functionality using regular expressions. The regex replace works by specifying the string to modify, defining a regex pattern to match against, and providing a replacement substring.
๐ŸŒ
Python Tutorial
pythontutorial.net โ€บ home โ€บ python regex โ€บ python regex sub()
Python Regex sub() Function
December 10, 2021 - Besides a regular expression, the pattern can be Pattern object. ... count parameter specifies the maximum number of matches that the sub() function should replace. If you pass zero to the count parameter or completely skip it, the sub() function will replace all the matches.
๐ŸŒ
DEV Community
dev.to โ€บ doridoro โ€บ python-differences-between-replace-and-resub-methods-1cfj
Python: differences between `.replace()` and `.re.sub()` methods - DEV Community
July 30, 2024 - Example: re.sub(r'\bworld\b', 'Python', 'hello world') results in 'hello Python'. ... Only supports simple string matching. Cannot use regular expressions or complex patterns. Replaces all occurrences of the substring if count is not specified.
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ python-regex-replace
Python regex: How to search and replace strings | Flexiple - Flexiple
import re str = "Joe-Kim Ema Max Aby Liza" print(re.sub("(\s)|(-)", ", ", str)) ... If you want to replace multiple patterns with different replacements, regex can be used.
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ python regex re.sub()
Python Regex re.sub() - Be on the Right Side of Change
June 13, 2023 - The re.sub(pattern, repl, string, count=0, flags=0) method returns a new string where all occurrences of the pattern in the old string are replaced by repl. Read more in our blog tutorial.
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-re-sub
Python re.sub() - Replace using Regular Expression
In this tutorial of Python Examples, we learned how to use re.sub() function to replace or substitute all the matchings for a given pattern in a string with the replacement string, with the help of example programs.
๐ŸŒ
Squash
squash.io โ€บ replacing-strings-in-python-using-re-sub
How to Replace Strings in Python using re.sub
Substitutions ... The function takes a pattern that it looks for in the provided string. Once located, it replaces the pattern with the repl argument. The count argument defines how many occurrences of the pattern are replaced, with the default being all occurrences (0). The flags argument can modify the pattern matching, for instance making it case-insensitive. Related Article: How to Use Python's Numpy.Linalg.Norm Function