Re: hot to use perg_match with multi strign patern

From: Date: Wed, 07 May 2003 19:53:27 +0000
Subject: Re: hot to use perg_match with multi strign patern
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-146639@lists.php.net to get a copy of this message
Dear Ernes, Thanks for help, it is working very good with preg_match. But when I try same thing with eregi, it is not working any idea why? if (eregi("/\b(got|am)\b", $mesage, $matches)) "Ernest E Vogelsinger" <ernest@vogelsinger.at> wrote in message news:5.1.1.6.2.20030507100347.033298e0@mail.vogelsinger.at... > 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 (#146639) next »