开发者

PHP regular expressions: No ending delimiter '^' found in

开发者 https://www.devze.com 2023-02-03 00:02 出处:网络
I\'ve been having some trouble with regular expressions. This is my code $pattern = \"^([0-9]+)$\"; if (preg_match开发者_如何学运维($pattern, $input))

I've been having some trouble with regular expressions.

This is my code

$pattern = "^([0-9]+)$";

if (preg_match开发者_如何学运维($pattern, $input))
   echo "yes";
else
   echo "nope";

I run it and get:

Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in


PHP regex strings need delimiters. Try:

$numpattern="/^([0-9]+)$/";

Also, note that you have a lower case o, not a zero. In addition, if you're just validating, you don't need the capturing group, and can simplify the regex to /^\d+$/.

Example: http://ideone.com/Ec3zh

See also: PHP - Delimiters


Your regex pattern needs to be in delimiters:

$numpattern="/^([0-9]+)$/";
0

精彩评论

暂无评论...
验证码 换一张
取 消