Skip to content Skip to sidebar Skip to footer

Extract Street Address From A String

Is there any way to extract a street address from a string (say, email) using python? The address does not come in a set format. It can come without state, zip code, city, but I ca

Solution 1:

As you already say yourself, an address can come in a large number of formats. And the reality is actually even worse if you take addresses from other countries into account. So no, there is not really a good way to parse and clean up such addresses. The larger the regional area is you want to include as possible formats, the more complicated it gets.

If you want to send the address to Google Maps anyway, then just send your original format. Google has enough data to extract the more useful parts and make the best possible out of it. As you are sending it to Google anyway, you can just do it in the first place.

Solution 2:

Addresses often follow a format, which can be exploited using regex. This is tricky, so luckily there is a wonderful library to make it easier for you.

pip install commonregex

Then

from commonregex import CommonRegex
parsed_text = CommonRegex("123 Your Street")
print(parsed_text.street_addresses)

Solution 3:

a = re.split(r"[\s\-:\\/_,]", "string address here !")
a1 = ""for i in a:
    if re.findall(r"[^\W]",i):
        a1 += i + " "print(a1)

Try to send this to google.

Post a Comment for "Extract Street Address From A String"