Home >Backend Development >PHP Tutorial >php正则匹配为什么不成功

php正则匹配为什么不成功

WBOY
WBOYOriginal
2016-06-13 11:48:091248browse

php正则匹配为什么不成功?求助
if(preg_match("^[a-zA-Z][a-zA-Z0-9_\-]{5,19}$", "abc-mmm") )
    echo "true";
else echo "false";

?>

想验证账号的正则表达式,字母开头,允许数字,字母,下划线,减号,6-20为,这个表达式为啥不成功啊?

Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in test.php on line 3
false

试过"^[a-zA-Z][a-zA-Z0-9_-]{5,19}$",取掉“\”也不对,求大神知道(utf8格式的)
------解决方案--------------------
那个叫定界符。不加定界符的话,PHP就认定为^[a-zA-Z][a-zA-Z0-9_-]{5,19}$是字符串,而不是变量。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn