<?php
$str = 'indistinct';
if (preg_match('/[^in]distinct/',$str)) {
    echo "OK";
} else {
    echo "Error";
}
?>
给分给分

解决方案 »

  1.   

    呵呵,你的[^in]岂不是把 "i"和"n"都否决了?
      

  2.   

    对不起,补充一下,我的问题背景是这样的:想写一个比较通用的统计recordcount的方法原本用"select count(0) ".strstr($sSQL,"from")来取,可是碰上有distinct的情况就不灵光了,后来写成eregi(" distinct +[[:alnum:]]+",$sSQL,$reg) or $reg[0]="0";
    $sSQL="select count(".$reg[0].") ".strstr($query,"from");结果碰上"select * from t1 where f1 in (select distinct f1 from t2)",又不行了现在eregi($patten,$sSQL,$reg),想求$patten的写法
      

  3.   

    哦,不好意思,上边写的$query,应该改成$sSQL :(
      

  4.   

    这下好了吧$str = 'indistinct';
    if (preg_match('/(^in)distinct/',$str)) {
        echo "Error";
    } else {
        echo "OK";
    }
      

  5.   

    不好意思,这样不符合我的原意呀eregi(" distinct +[[:alnum:]]+",$sSQL,$reg) or $reg[0]="0";
    $sSQL="select count(".$reg[0].") ".strstr($sSQL,"from");我想让$reg[0]的值为"distinct 字段名"……谢谢
      

  6.   

    不太明白你的意思。
    首先mysql并不支持这个写法:"select * from t1 where f1 in (select distinct f1 from t2)",所以也无通用可言了。
    其次,在你的表达式中并未出现(),所以在eregi(" distinct +[[:alnum:]]+",$sSQL,$reg)后,$reg是无效的。
    取出select的后的字段列表,只需排除distinct即可
      

  7.   

    后台是oracle
    没有(),也能用呀,在只匹配一个东西的情况下
      

  8.   

    排除了distinct,数目便不对了
      

  9.   

    算了,我最后写成这样if (!eregi(".+( in )*.+( distinct .+ )",$sSQL,$reg) or $reg[1])
    {
       $reg[2]="0";
    }
    $sSQL="select count(".$reg[2].") ".strstr($sSQL,"from");应该是可以了,谢谢大家