Hey, I was wondering how I can find a Street Address in a string in Python/Ruby?
Perhaps by a regex?
Also, it's gonna be in the following format (US)
420 Fanboy Lane, Cupertino CA
Thanks!
Maybe you want to have a look at pypostal. pypostal are the official Python bindings to libpostal.
With the Examples from Mike Bethany i made this little Example:
from postal.parser import parse_address
addresses = [
"420 Fanboy Lane, Cupertino CA 12345",
"1829 William Tell Oveture, by Gioachino Rossini 88421",
"114801 Western East Avenue Apt. B32, Funky Township CA 12345",
"1 Infinite Loop, Cupertino CA 12345-1234",
"420 time!",
]
for address in addresses:
print parse_address(address)
print "*" * 60
> [(u'420', u'house_number'), (u'fanboy lane', u'road'), (u'cupertino', u'city'), (u'ca', u'state'), (u'12345', u'postcode')]
> ************************************************************
> [(u'1829', u'house_number'), (u'william tell', u'road'), (u'oveture by gioachino', u'house'), (u'rossini', u'road'), (u'88421',
> u'postcode')]
> ************************************************************
> [(u'114801', u'house_number'), (u'western east avenue apt.', u'road'), (u'b32', u'postcode'), (u'funky', u'road'), (u'township',
> u'city'), (u'ca', u'state'), (u'12345', u'postcode')]
> ************************************************************
> [(u'1', u'house_number'), (u'infinite loop', u'road'), (u'cupertino', u'city'), (u'ca', u'state'), (u'12345-1234',
> u'postcode')]
> ************************************************************
> [(u'420', u'house_number'), (u'time !', u'house')]
> ************************************************************
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With