<body onload="init();">
<div id="temp" style="">
####PostList?modelclassID=3&deptID=1&current_page=1&page_rows=1&forum_id=5####
####PostList?modelclassID=3&deptID=2&current_page=1&page_rows=2&forum_id=4####
####PostList?modelclassID=3&deptID=3&current_page=1&page_rows=3&forum_id=4####
####PostList?modelclassID=3&deptID=4&current_page=1&page_rows=4&forum_id=4####
####PostList?modelclassID=3&deptID=5&current_page=1&page_rows=5&forum_id=45147####
</div></body>以上是我在网页中的一段代码,这个网页是用servlet从HTML文件中读取的,用正则表达式匹配“####PostList?modelclassID=3&deptID=1&current_page=1&page_rows=1&forum_id=5####”这个字符串,应该匹配出5个字符串,
这是我用的正则表达式“(####\\w+\\?(\\w+=\\w+&?)+####)”,怎么样不用循环,一次匹配出这5个字符串啊

解决方案 »

  1.   

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class html
    {
    public static void main(String[] a)
    {
    String htmlcode ="<div id=\"temp\" style=\"\">"+
           " ####PostList?modelclassID=3&deptID=1&current_page=1&page_rows=1&forum_id=5#### " +
    "####PostList?modelclassID=3&deptID=2&current_page=1&page_rows=2&forum_id=4#### " +
      " ####PostList?modelclassID=3&deptID=3&current_page=1&page_rows=3&forum_id=4#### " +
      " ####PostList?modelclassID=3&deptID=4&current_page=1&page_rows=4&forum_id=4#### " +
      " ####PostList?modelclassID=3&deptID=5&current_page=1&page_rows=5&forum_id=45147#### " +
       " </div></body> "; Pattern pattern = Pattern.compile("####(.*?)####");
    Matcher m = pattern.matcher(htmlcode); while (m.find())
    {
    System.out.println(m.group(1));
    } }
    }