I'm new to Regex and am trying to use it to parse apart addresses into House Number and Street.
Example: 123 Main St --> ['123', 'Main St']
It gets slightly complicated by the fact that some of my street strings will have hyphenated street addresses, in which case I want to take the first number before the hyphen.
Example: 123-127 Main St --> ['123', 'Main St']
Lastly, I need to be able to handle street names that start with a number.
Most complicated example being: 123-127 3rd Ave --> ['123', '3rd Ave']
So far I've been able to extract the street number, including in the hyphenated scenario, but I'm unsure how to extract the street name which comes after matching the street number pattern.
MyString='123-127 Main St'
StreetNum=digit=re.findall('(^\d+)', MyString)
Thanks for the help!
Am also editing the question to point out that a dash is not the only character that can separate streets with two numbers. There are three total situations that come up in the data:
1) 123-127 5th St
2) 123 1/2 5th St
3) 123 & 125 5th St
In all 3 of these situations the result should be 123 5th St.
Hope this is what you're looking for:
(\d+).*?\s+(.+)
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