Introduction:
Script use to get the pincode from a address. I used regulatr expression to find it. At first, we will check check pincode end of address. If we didn't get, then check between address. Here I assumed pincode starts with 7 and len should be 6 (ex 700002)
Script:
def getPin(myStr):
pin=re.search(r"7(\d{0,5})$",myStr)# check for pincode end of string
if not pin:
pin=re.search(r"7(\d{0,5})[ ]",myStr) # check for pincode in between string
if pin:
return pin.group().strip()
else:
return ''
Labels: Python
Subscribe to:
Posts (Atom)