Re: preg_match() oddities and question [message #176079 is a reply to message #176077] |
Tue, 22 November 2011 17:30 |
The Natural Philosoph
Messages: 993 Registered: September 2010
Karma:
|
Senior Member |
|
|
Thomas 'PointedEars' Lahn wrote:
> Sandman wrote:
>
>> Thomas 'PointedEars' Lahn <PointedEars(at)web(dot)de> wrote:
>>> Sandman wrote:
>>>> So I have this regexp:
>>>>
>>>> if (preg_match("/^(.*?)\s*(\d*?)\s*([A-Z,a-z,-]*?)$/", $search, $m)){
>>>> $streetname = uc_words($m[1]);
>>>> $streetnumber = trim($m[2]);
>>>> $streetletter = strtoupper($m[3]);
>>>> $search = trim($streetname . SPACE . $streetnumber .
>>>> $streetletter);
>>>> }
>>>>
>>>> The desired result is taki9ng the input ($search) and split it into
>>>> its parts as an address, right? $search can be, for example, "foo
>>>> street 34", "longstreet 45b", "longstreet 45 b" or just "longstreet".
>>> "10 East 42nd Street, New York, NY 10017, USA".
>> That wouldn't be a normal swedish address, no. :)
>
> You had not limited the country or the language of your street addresses.
>
> My point is that parsing a street name and a house number from a street
> address is a hard problem that cannot be solved only by applying one regular
> expression.
>
Quite right. Is worse than you can possibly iagine at leats here in te
UK, where addresses can be as little as 2 lines long or up to 6..
So
10 Wonkers place, LONDON EC3 7QY is a typical TOWN address
Out in the sticks you might get
Apartment 4b, the Old Town House, Shire Lane, Recketts Green, Nr
Stonehouse, Gloucestershire GL13 6AH
And if that comes at you without commas, god help you.
I have spent DAYS taking name/address fields and parsing them *manually*
into structured tables...
>
> PointedEars
|
|
|