import re
regex = re.compile(r"\b(?!100)\d{6,9}")
test_str = ("123456789012\n\n"
"Don't match: 10012345\n\n"
"Match: 1045677\n\n"
"Don't match:\n\n"
"1004567\n\n"
"Don't match: num=\"10034567\" test\n\n"
"Match just the middle number in the line: num=\"10048876\" 1200476, 1008888")
subst = "*"
result = regex.sub(subst, test_str)
if result:
print(result)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html