[nycphp-talk] Regex & Delimiter Trouble
Dan Cech
dcech at phpwerx.net
Fri Nov 19 16:30:05 EST 2004
Use single quotes, the $ is screwing up the regex.
$pattern = '/^quantity[1-9][0-9]{0,2}$/';
Dan
Daniel J Cain Jr. wrote:
> Given this script:
>
> <?php
> $pattern = "/^quantity[1-9][0-9]{0,2}$/";
> $haystack = "quantity11";
> echo (preg_match($haystack, $pattern)) ? 'We got one!': 'DOH!', "\n";
> ?>
>
> I hope to match quantity1 ... quantity999, but PHP5 on Mac OS X outputs
> the following from the CLI:
>
> Warning: preg_match(): Delimiter must not be alphanumeric or backslash
> in /Users/djcain/regex on line 4
> DOH!
>
> I've been trying to get around the issue for quite some time now and I
> think I'm unable to see the forest through the trees :)
>
> The warning seems pretty straightforward but for the life of me I'm
> unable to grasp what it want's for the delimiter. Anyone out there
> dealt with this issue before, or see the problem that I apparently do not?
>
> -dan
>
> _______________________________________________
> New York PHP Talk
> Supporting AMP Technology (Apache/MySQL/PHP)
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.newyorkphp.org
More information about the talk
mailing list