像这样一个字符串
&ch=1005&kind=941,2323,8097&row=20&ShowDate=2&table=1&author=1&all=<url >想要提取出kind对应的几个值,值可以有很多个,甚至是没有值(就是没有kind这项)而且kind出现的位置也不固定...请问各位高人有什么好办法?用正则表达式的话要怎么做呢?

解决方案 »

  1.   

    用"&"把字符串分割.
    看哪个子字符串是以kind开头的.
      

  2.   

    String str = "&ch=1005&kind=941,2323,8097&row=20&kind=2&table=1&author=1&kind=<url >";
    CharSequence inputStr = str.subSequence(0, str.length());
    String patternStr = "&kind=([^&]+)";
        
    // Compile regular expression
    Pattern pattern = Pattern.compile(patternStr);
    Matcher matcher = pattern.matcher(inputStr);        
    while (matcher.find()) {
           // Get the match result
           String replaceStr = matcher.group();
           replaceStr = replaceStr.replaceAll(patternStr,"$1");            
           System.out.println(replaceStr);
    }
      

  3.   

    还是说要这个?
    String url = "&ch=1005&kind=941,2323,8097&row=20&ShowDate=2&table=1&author=1&all=<url >";
    url = url.replaceAll(".+&kind=([^&]+).+", "$1");
    String[] result = url.split(",");
    for (int i = 0; i < result.length; i++) {
       System.out.println(result[i]);
    }
      

  4.   

    oh 谢谢各位  尤其是malligator了...