JAVA正则表达式替换字符串问题



public static void main(String[] args) {


String regex = "<!-- start_page -->[\\s\\S]*<!-- end_page -->";


String str = "dsagfg<!-- start_page -->dsgdr <!-- end_page -->sdafdgrtuy";
Pattern pat = Pattern.compile(regex);
Matcher matcher = pat.matcher(str);
while (matcher.find()) {
String temp = str.substring(matcher.start(), matcher.end());
System.out.println(temp);
str = str.replaceAll(temp, "");
matcher = pat.matcher(str);
}
System.out.println(str);
}

你可能感兴趣的:(JAVA正则表达式替换字符串问题)