I am trying to separate street names from street numbers which have these patterns:
What is the regex to get the street name, and the regex to get the street number in php and python?
Note: The number is always after the street name so I guess that should shorten it.
Thanks.
Just write into the blanks, in order, the usual way that your addresses written. Don't be concerned about the caption that says "street number" or Town" or "ZIP Code" or whatever. Usually there are enough blanks to enter each of the items of your actual address. If not, put two items in one blank space.
Here are two ways to do it. Mouse and Keyboard: Click the letter above the column where the address info is, and it'll select the entire column. Keyboard Shortcut: Select any cell from the column that has the address info. Then press and hold Ctrl, and hit Space.
I would suggest that the best way to determine when the number starts is when you hit a digit. Thus, you would use
preg_match('/^([^\d]*[^\d\s]) *(\d.*)$/', $address, $match)
Examples:
'Bubbletown 145' => 'Bubbletown', '145'
'Circlet56a' => 'Circle', '56a'
'Bloomfield Avenue 68' => 'Bloomfield Avenue', '68'
'Quibbit Ave 999a' => 'Quibbit Ave', '999a'
'Singletown551abc' => 'Singletown', '551abc'
It will probably be best for you to consider how you want edge cases to be handled, then write a unit test to test your own Regex function.
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