PHP 正则表达式:找不到结束分隔符“^" [英] PHP regular expressions: No ending delimiter '^' found in

查看:45
本文介绍了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 - 分隔符

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

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