如:http://www.test.net/scripts/index.php?ID=15  
    http://test.net/scripts/index.php?ID=236
要求找出这种规则的字符串 其中ID参数不固定,也不知道是多少位,http://www.test.net/scripts/index.php?PC=1&KE=ulvmpxik
http://test.net/scripts/index.php?PC=1&KE=ulafecdgf
要求找出这种规则的字符串 其中PC参数不固定,也不知道是多少位,KE参数也不固定 也不知是多少位

解决方案 »

  1.   

    第一个是,http://www.abc123.com.cn/m/def123
    前半段:"http://www.abc123.com.cn/m"这个格式是固定的,后面"def123"是不一定的,但绝对会大于三位,求这么一个正则,谢谢.第二个是,http://def123.service.abc123.com/
    是以"http://"开头,以"service.abc123.com"结尾,中间“def123”是不确定的,但绝对会大于三位,不知该怎么写,谢谢大家了。一直在线。望不吝指教。$str = "http://www.abc123.com.cn/m/def23";
    preg_match("/^http.*www.abc123.com.cn/m/(w{3,})/is",$str,$m);
    print_r($m);
    $str2 = "http://def123.service.abc123.com/";
    preg_match("/^http://(w{3,}).service.abc123.com/$/",$str2,$m2);
    print_r($m2);
    希望这个对你有帮助!
      

  2.   


    我从网上找到了匹配url的正则表达式如下:
    http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
     
      

  3.   

    上面的最后如果是数字,用
    http://(www\.)?test\.net/scripts/index\.php\?ID=\d+
    如果不确定,用
    http://(www\.)?test\.net/scripts/index\.php\?ID=[^\s]+下面的用
    http://(www\.)?test\.net/scripts/index\.php\?PC=\d+&KE=\w+
    或者
    http://(www\.)?test\.net/scripts/index\.php\?PC=.+?&KE=[^\s]+
      

  4.   

    http://www.test.net/scripts/index.php?ID=15      
           http://test.net/scripts/index.php?ID=236  
    这个要最后是以数字结束 并且含有ID这个参数的呀 http://www.test.net/scripts/index.php?PC=1&KE=ulvmpxik  
    http://test.net/scripts/index.php?PC=1&KE=ulafecdgf  这个就按一般的URL规则,但是必须要有PC和KE在里面的呀
      

  5.   

    我所写的那你个都符合你的要求的,只是前一个范围小点,后一个范围大点
    算了,就用这两个吧
    http://(www\.)?test\.net/scripts/index\.php\?ID=\d+
    http://(www\.)?test\.net/scripts/index\.php\?PC=.+?&KE=\w+有不符合的再提出来