Python @ DjangoSpin

PyPro #94 Remove leading zeroes from parts of an IP address

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

Remove leading zeroes from parts of an IP address in Python

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.


See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply