写一个正则表达式判断下面 两个网址格式正则表达式 正确, 最后一个错误http://www.theabc.com   
gou4u.com.cn/dsfas/sdf/de3.php?daf=333&df=11gou4u.c8m.cn 
我 写到下面, 写不下去了.....  特别是 第二个 不知道 怎么写.
^([a-zA-Z]+://)?(\w+(-\w+)*)(\.(\w+(-\w+)*))(\.[a-zA-Z]*){1,2}((\/\w_)*)?

解决方案 »

  1.   

    你写一个只能匹配最后一个的正则,如果匹配,输出错误,否则输出正确不就行了。
    if(preg_match('/^gou4u.c8m.cn$/',$str)){
        echo '网址错误';
    }else{
        echo '网址正确';
    }  
      

  2.   

    写一个正则判断  gou4u.c8m.cn 这个  错误 http://www.theabc.com  
    gou4u.com.cn/dsfas/sdf/de3.php?daf=333&df=11这两个正确
    要类似
    ^([a-zA-Z]+://)?(\w+(-\w+)*)(\.(\w+(-\w+)*))(\.[a-zA-Z]*){1,2}((\/\w_)*)?...........这样的,不是1楼的那种 
      

  3.   

    $str='http://www.theabc.com';//字符串自行修改
    $patten='/([a-zA-Z]+:\/\/)?([w]{3}\.\w+\.\w+)|((.+)[\/\w\.]+\?\w+=\d+&\w+=\d+)/i';
    if(preg_match($patten,$str)){
      echo '网址正确';
    }else{
      echo '网址错误';
      

  4.   

    =\d+)/i';   
    i ?  what is the i  ?