试试这个应该可以String src = "<html>...很多行..</html>..."; String regx = "[ |\\S]*"; //注\S匹配非空格字符, Pattern p = Pattern.compile(rex); Matcher m = p.matcher(src); while (m.find()) { System.out.println(m.group()); }
需要指定匹配模式,就是下面的常量Pattern.compile(rex, CONSTANT_XXX);CASE_INSENSITIVE, MULTILINE, DOTALL, UNICODE_CASE, and CANON_EQ Compiles the given regular expression into a pattern with the given flags. Parameters: regex The expression to be compiled flags Match flags, a bit mask that may include CASE_INSENSITIVE, MULTILINE, DOTALL, UNICODE_CASE, and CANON_EQ Throws: IllegalArgumentException If bit values other than those corresponding to the defined match flags are set in flags PatternSyntaxException If the expression's syntax is invalid
这个也不行!<(.*)>.*<\/\1>
这个只能匹配同一行的HTML 标记,我希望匹配多行的
怎么实现,用java???
String regx = "[ |\\S]*"; //注\S匹配非空格字符,
Pattern p = Pattern.compile(rex);
Matcher m = p.matcher(src);
while (m.find()) {
System.out.println(m.group());
}
Compiles the given regular expression into a pattern with the given flags. Parameters:
regex The expression to be compiled
flags Match flags, a bit mask that may include CASE_INSENSITIVE, MULTILINE, DOTALL, UNICODE_CASE, and CANON_EQ
Throws:
IllegalArgumentException If bit values other than those corresponding to the defined match flags are set in flags
PatternSyntaxException If the expression's syntax is invalid