求一正式表?式,字符串只能包含 英文、?字、下??和""

WBOY
Release: 2016-06-23 13:32:08
Original
920 people have browsed it

?有一字符串需要判?,字符串只能包含 英文、?字、下??和"\",???如何??正式表?式,??。


回复讨论(解决方案)

/^[\w\\]+$/

/^[\w\\]+$/



您好,我采用了??方法,但程序??了,麻??看看

echo " ";
function ispassword($str) {

if(preg_match('/^[\w\\]+$/',$str)){
return true;
}else {
return false;
}
}
$password = 'this_is_test_\thisstr';
if(ispassword($password)) {
echo '符合';
}else {
echo '不符合';
}

?>

程序??:( ! ) Warning: preg_match() [function.preg-match]: Compilation failed: missing terminating ] for character class at offset 8

我把 if(preg_match('/^[\w\\]+$/',$str)) 改? if(preg_match('/^[\w\\\]+$/',$str)) ?行正常了。是否漏了?\的原因呢?

是的
这与 php 版本有关

是的
这与 php 版本有关



??版主。。??。。
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!