Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Sandman Newsgroups: comp.lang.php Subject: Re: preg_match() oddities and question Date: Wed, 23 Nov 2011 09:55:22 +0100 Lines: 41 Message-ID: References: <1670168.aK4W3vaeNJ@PointedEars.de> <3004614.SPkdTlGXAF@PointedEars.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: individual.net zJiwq6rF+lVA/pRoCSndYwnFTzAcqCfQmKb8MSEHCeELAO7hM= X-Orig-Path: mr Cancel-Lock: sha1:TIydMmAjtsFzx3dWjDpdL5S7ygQ= User-Agent: MT-NewsWatcher/3.5.2 (Intel Mac OS X) X-Face: $@,Vfa$,)%=Qa7L]y)&oZj_\EiHc}}Af0Bei"4a_%)"c6TQ+P/:53>;PNGuWUmkqyeN-qM65foJ[;T_(k;>]&G\T4Lhm:2 ujye2_,iUJFE;NZn>y;.|-hl7g~bIOF1qG\o, Thomas 'PointedEars' Lahn 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. Well, to my defense, the subject line was "preg_match() and swedish characters" until I changed it. I hadn't changed it when I wrote my examples. > 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. Right, but your example is not a valid argument for that conclusion. My examples contained the variations of addresses that I wanted to match. Or are you saying that there is no way to use regular expressions to catch the examples I gave? Because I have a hard time believing that. -- Sandman[.net]