PHP正则表达式:在中找不到结尾定界符'^' [英] PHP regular expressions: No ending delimiter '^' found in

查看:94
本文介绍了PHP正则表达式:在中找不到结尾定界符'^'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用正则表达式时遇到了麻烦.

I've been having some trouble with regular expressions.

这是我的代码

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

if (preg_match($pattern, $input))
   echo "yes";
else
   echo "nope";

我运行它并得到:

警告:preg_match()[function.preg-match]:在

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

推荐答案

PHP正则表达式字符串需要定界符.试试:

PHP regex strings need delimiters. Try:

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

此外,请注意,您使用的是小写字母o,而不是零.另外,如果您只是进行验证,则不需要捕获组,并且可以将正则表达式简化为/^\d+$/.

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+$/.

示例: http://ideone.com/Ec3zh

另请参见: PHP-分隔符

See also: PHP - Delimiters

这篇关于PHP正则表达式:在中找不到结尾定界符'^'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆