Re: preg_match problem

From: Date: Mon, 30 Sep 2002 07:58:04 +0000
Subject: Re: preg_match problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-118176@lists.php.net to get a copy of this message
Chris You can retrieve the word strings using the brackets ie specifying where there should and shouldnt be brackets. So you need to change (.+)\s+\((.+)\) to ([^()]+)\s\\(([^()]+)\\)\s\\(([^()]+)\\) explained:- ( = start capture [^()]+ = 1 or more characters but no brackets ) = end of capture (Some silly Text) \s = space \\( = left bracket ( = start capture [^()]+ = 1 or more charcters but no brackets ) = end capture (First) \\) = right bracket \s\\(([^()]+)\\) = space and repeat the last capture to get Second Debbie ----- Original Message ----- From: "Chris N" <us_spork@hotmail.com> To: <php-general@lists.php.net> Sent: Monday, September 30, 2002 6:14 AM Subject: [PHP] preg_match problem > Ok heres the situation, I have a string like this > > $this->_item["title"] = "28.09.02 - Some silly Text (First) (Second)"; > > Im trying to do a preg_match on it to check it to make sure its in a certian > format. Heres my preg_match > > preg_match("/^(\d+)\.(\d+)\.(\d+)\s+\-\s+(.+)\s+\((.+)\)$", > $this->_item["title"], $matches); > list($all, $one, $two, $three, $four, $five) = $matches; > > What Im getting returned in this > > $one = 28 > $two = 09 > $three = 02 > $four = Some silly Text > $five = First) (Second > > What I want is > > $four = Some silly Text (First) > $five = Second > > Can anyone see where Im going wrong? The match may be really crude, Im still > pretty new to regular expressions. But it works just fine as long as there > is only one set of (). > > Chris N. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#118176) next »