这个涉及正则的简单功能怎么实现?
判断一个字符串(这个字符串只能包含下面三种字符)
1. 26个英文字母
2. “0,1,2,3,4,5,6,7,8,9”十个数字
3. “-”(英文中的连词号)
------解决方案--------------------
$str="/[^0-9a-zA-Z]/i";
------解决方案--------------------
汗楼撒谎那个掉了“―”
$str="/[^0-9a-zA-Z_]/i";
------解决方案--------------------
楼上的是错的。
如果是判断不存在的,那么 '-' 这个不算?
有 i 修饰,又何需 a-zA-Z 呢?
/^[a-z0-9-]+$/i
------解决方案--------------------
preg_match('/[-a-z0-9]+/i',$str); //$str 是你要匹配的字符串
<br><font color="#e78608">------解决方案--------------------</font><br>
<a style="color:#f60; text-decoration:underline;" title="php" href="https://www.php.cn/zt/15714.html" target="_blank">php</a>
$str="jsd-fowfmf564c-s1f23";
$pattern='/^[a-z0-9-]+$/i';//用的楼上的楼上
preg_match($pattern,$str,$result);
if($result)
{
echo "匹配";
};
?>
<br><font color="#e78608">------解决方案--------------------</font><br>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号