Re: Same pattern, ereg_replace catches it, ereg doesn't
| From: | Curt Zirzow | Date: | Fri, 25 Jul 2003 04:24:45 +0000 |
| Subject: | Re: Same pattern, ereg_replace catches it, ereg doesn't | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-156782@lists.php.net to get a copy of this message | ||
* Thus wrote Reuben D. Budiardja (reubendb@innovativethought.com):
>
> Hi all,
> My guess is I miss something really dumb, but here is my problem. I want to
> use ereg to find some pattern, but it doesn't seems to work. The same pattern
> uses with ereg_replace, works fine and replaced the pattern. Here is my code,
> and the output:
>
> <?
> $string = "This is a %ANS[1] test, and %ANS[2] test, and %ANS[10], test";
> echo "String is: $string\n";
>
> $pattern = "%ANS[[0-9]+]";
Should be:
'%ANS\[[0-9]+\]'
note also the single quote to avoid needing to avoid escaping the escape:
what you have i think would match:
%ANS9
or
%ANS+
I'm not sure how the nested character classes work with ereg.
Also I would look at the PCRE functions, they are in general faster
than the standard ereg* functions. Unless you require a POSIX
compatible script.
HTH,
Curt
--
"I used to think I was indecisive, but now I'm not so sure."