<body onload="init();">
<div id="temp" style="">
####PostList?modelclassID=3&deptID=1¤t_page=1&page_rows=1&forum_id=5####
####PostList?modelclassID=3&deptID=2¤t_page=1&page_rows=2&forum_id=4####
####PostList?modelclassID=3&deptID=3¤t_page=1&page_rows=3&forum_id=4####
####PostList?modelclassID=3&deptID=4¤t_page=1&page_rows=4&forum_id=4####
####PostList?modelclassID=3&deptID=5¤t_page=1&page_rows=5&forum_id=45147####
</div></body>以上是我在网页中的一段代码,这个网页是用servlet从HTML文件中读取的,用正则表达式匹配“####PostList?modelclassID=3&deptID=1¤t_page=1&page_rows=1&forum_id=5####”这个字符串,应该匹配出5个字符串,
这是我用的正则表达式“(####\\w+\\?(\\w+=\\w+&?)+####)”,怎么样不用循环,一次匹配出这5个字符串啊
<div id="temp" style="">
####PostList?modelclassID=3&deptID=1¤t_page=1&page_rows=1&forum_id=5####
####PostList?modelclassID=3&deptID=2¤t_page=1&page_rows=2&forum_id=4####
####PostList?modelclassID=3&deptID=3¤t_page=1&page_rows=3&forum_id=4####
####PostList?modelclassID=3&deptID=4¤t_page=1&page_rows=4&forum_id=4####
####PostList?modelclassID=3&deptID=5¤t_page=1&page_rows=5&forum_id=45147####
</div></body>以上是我在网页中的一段代码,这个网页是用servlet从HTML文件中读取的,用正则表达式匹配“####PostList?modelclassID=3&deptID=1¤t_page=1&page_rows=1&forum_id=5####”这个字符串,应该匹配出5个字符串,
这是我用的正则表达式“(####\\w+\\?(\\w+=\\w+&?)+####)”,怎么样不用循环,一次匹配出这5个字符串啊
import java.util.regex.Matcher;
import java.util.regex.Pattern; ... String str = "####PostList?modelclassID=3&deptID=1¤t_page=1&page_rows=1&forum_id=5####"
+ "####PostList?modelclassID=3&deptID=2¤t_page=1&page_rows=2&forum_id=4####"
+ "####PostList?modelclassID=3&deptID=3¤t_page=1&page_rows=3&forum_id=4####"
+ "####PostList?modelclassID=3&deptID=4¤t_page=1&page_rows=4&forum_id=4####"
+ "####PostList?modelclassID=3&deptID=5¤t_page=1&page_rows=5&forum_id=45147####";
String regex = "####\\w+\\?(\\w+=\\w+&?)+####";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
while (matcher.find())
System.out.println(matcher.group());
不知道这样行不行,没装jdk
####\\w+\\?(\\w+=\\w+&?)+####\\s+####\\w+\\?(\\w+=\\w+&?)+####\\s+####\\w+\\?(\\w+=\\w+&?)+####\\s+####\\w+\\?(\\w+=\\w+&?)+####\\s+####\\w+\\?(\\w+=\\w+&?)+####
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
while (matcher.find())
System.out.println(matcher.group(1));
Pattern p = Pattern.compile(r);
Matcher m = p.matcher(str);
m.find();
System.out.println(m.group(1));
System.out.println(m.group(2));
System.out.println(m.group(3));
System.out.println(m.group(4));
System.out.println(m.group(5));