Reading Time: 1 minutes
Remove leading zeroes from parts of an IP address in Python
Write a Regular Expression in Python to remove leading zeroes from parts of an IP address.
import re sampleIP = '192.168.01.01' print( re.sub('\.[0]*', '.', sampleIP) ) # '192.168.1.1'
To learn more about Regular Expressions in Python, click here.