import re
strings = ["0.0.4.1", "7.51.4.1", "0.1.4.1", "001", "0.1", ".0.1", "0.0.0.0", "0.1.2.3.4.5"]
pattern = r"^(?=\d+(?:\.\d+){3}$)0+\.(?:0+\.)*"
for s in strings:
    print(re.sub(pattern, "", s))