Re: hot to use perg_match with multi strign patern
| From: | SLanger at spirit21 dot de | Date: | Wed, 07 May 2003 09:06:32 +0000 |
| Subject: | Re: hot to use perg_match with multi strign patern | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-146629@lists.php.net to get a copy of this message | ||
Hello
Your problem is the pattern itself.
>if (preg_match("/(yes)?(no)/i", $mesage, $matches)) {
> print "refusee - $matches[0]";
>} else {
> print "negative";
>};
Your pattern tells the regex to find any 'no' in a text. Since the yes is
optional the regex will never check for it. In other words the ()? part is
skipped and the no part is tested since the pattern can only match if a no
is in the text. The regex will see this and simply ignore the (yes)?.
What you probably want is to use alternatives making your pattern look
like /(?:yes|no)/i. This way either yes or no is found. Beaware that if
you do want to do this it will probably faster to use a string function to
find literal occurences.
Regards
Stefan Langer