public class RegTest {
public static void main(String[] args){
String regex = "\\[([\\s\\S]*?)\\[";
String str = "[begin]111[end] [begin]222[end] [begin]333[end] ";
getQuestionResolution(regex, str);
System.out.println("------------------------");
String regex2 = "\\[([\\s\\S]*)\\[";
getQuestionResolution(regex2, str);
}
private static void getQuestionResolution(String regex,String html){
Matcher matcher = Pattern.compile(regex).matcher(html);
while (matcher.find()){
//group是針對()來說的,group(0)就是指的整個串,group(1) 指的是第一個括號里的東西,group(2)指的第二個括號里的東西。
//group()= group(0)
System.out.println(matcher.group().trim());
} } }