RE: [PHP] pcre pattern match help

From: Date: Tue, 17 Dec 2002 23:21:02 +0000
Subject: RE: [PHP] pcre pattern match help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-128619@lists.php.net to get a copy of this message
> I would like to do a pattern match against a string, sometimes this > pattern > will include the full string, and sometimes it will not, if the pattern > does > not include the second match I still want to get the first pattern match. > > Below is my code, and the results I am looking for. > > Thanks in advance, > Max > > preg_match ("/\:\[(\S+)\]\:(\S*)/",$transport,$matches); Make the part after the closing ] optional. preg_match("/\:\[(\S+)\](\:(\S*))?/",$transport,$matches $matches[1] should be the IP and $matches[3] should be the port, if it exists. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/

« previous php.general (#128619) next »