高手!请帮忙 一个正则:字符串中包含a、b、c、d、e、f这6个字母中的任意4个或5个字母
万谢!
------解决方案--------------------
/[abcdef]{4,5}/
------解决方案--------------------
/[a-f]{4,5}/
允许重复的啊.
不允许重复的不会写正则, 只会写代码判断一下.
------解决方案--------------------
同上
------解决方案--------------------
- PHP code
$str="adcdel";
function filter($str)
{
preg_match('/^\S{6}$/',$str,$match);
if(!empty($match[0]))
preg_match('/[a-f]{4,5}/',$match[0],$matchs);
return $a=isset($matchs) ? $matchs[0]:null;
}
$result = filter($str);
if($result)
{
var_dump($result);
echo "[[success]]";
}else{
echo "[[failed]]";
}