import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "<!ENTITY\\s[a-z0-9]*\\s\"(&[a-zA-Z0-9]+;){4,}\">(?:.*?<!ENTITY\\s[a-z0-9]*\\s\"(&[a-zA-Z0-9]+;){4,}\">){4,}";
final String string = "<!DOCTYPE data [\n"
+ "<!ENTITY a0 \"dos\" >\n"
+ "<!ENTITY a1 \"&a0;&a0;&a0;&a0;\">\n"
+ "<!ENTITY a2 \"&a1;&a1;&a1;&a1;&a1;&a1;\">\n"
+ "<!ENTITY a1 \"&a2;&a2;&a2;&a2;&a2;&a2;\">\n"
+ "test\n"
+ "<!ENTITY a1 \"&a2;&a2;&a2;&ertertert;&a2;&a2;\">\n"
+ "<!ENTITY a1 \"&a2;&a2;&a2;&ertertert;&a2;&a2;\">\n\n\n"
+ "<!ENTITY a1 \"&a2;&a2;&a2;&a2;&a2;&a2;\">\n"
+ "d\n"
+ "dd\n\n"
+ "<html abc>\n"
+ "a\n\n"
+ "<!ENTITY a2 \"&a3;&a3;&a3;&a3;&a3;\">\n"
+ "<!ENTITY a1 \"&a0;&a0;&a0;&a0;&d5;\">\n"
+ "]>\n"
+ "<data>&a2;</data>";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html