Re: simple Regex

From: Date: Thu, 07 Dec 2000 11:27:37 +0000
Subject: Re: simple Regex
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-29096@lists.php.net to get a copy of this message
Delbono wrote: > > Hello. > > I've this string to parse: > Via Monticano Del COLLE > > How can I get the first three words? > > Logic: > > All words that are UCFirst_ and not words that are all CAPS > > ... > Maybe this way: <? $test = "Via Monticano Del COLLE"; preg_match_all( "/([A-Z][a-z0-9]+) ?/", $test, $regs, PREG_PATTERN_ORDER ); ?> Now, $regs[0] is array of full patterns, i.e ("Via ","Monticano ","Del ") and $regs[1] is array of strings matched by the first parenthesized subpattern, i.e ("Via","Monticano","Del"). See more: 'PHP Manual'->'LIV. Regular Expression Functions (Perl-Compatible)'->'preg_match_all'. Hope this helps. :) -- Pavel a.k.a. Papi

« previous php.general (#29096) next »