Re: hot to use perg_match with multi strign patern

From: Date: Wed, 07 May 2003 08:09:50 +0000
Subject: Re: hot to use perg_match with multi strign patern
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-146628@lists.php.net to get a copy of this message
At 19:59 07.05.2003, qt said: --------------------[snip]-------------------- >I want search more than one words in the string. I am trying to use >preg_match with following script but it is finding only last one. I wan to >find either yes or no. But it is finding only "no" not "yes". Actally I want >to check bad words in the string such as spelling. > >Where is my problem? > >if (preg_match("/(yes)?(no)/i", $mesage, $matches)) { --------------------[snip]-------------------- This expression will only match if there is a "no", optionally immediately preceded by "yes" (which renders useless - will always match a "no"). You want to use this: '/(yes|no)/i' Better yet add a "word boundary" before and after so you only match "Hey yes dear" and "Hey no dear", but not "Yesterday I had pizza" or "Nowadays it's a mess": '/\b(yes|no)\b/i' -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#146628) next »