import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?:(?<=^\\n)|(?<=\\A))\n"
+ "(?<list_all>\n"
+ " (?<list_prefix>\n"
+ " [\\s]{0,3}\n"
+ " (?<list_type_any>\n"
+ " (?:\n"
+ " (?<list_type_unordered_star>(?&list_unordered_star))\n"
+ " |\n"
+ " (?<list_type_unordered_minus>(?&list_unordered_minus))\n"
+ " |\n"
+ " (?<list_type_unordered_plus>(?&list_unordered_plus))\n"
+ " |\n"
+ " (?<list_type_ordered>(?&list_ordered))\n"
+ " )\n"
+ " )\n"
+ " [ \\t]+\n"
+ " )\n"
+ " (?<list_content>(?s:.+?))\n"
+ " (?<list_after>\n"
+ " \\z\n"
+ " |\n"
+ " \\n{2,}\n"
+ " (?=\\S)\n"
+ " (?!\n"
+ " [ \\t]*\n"
+ " (?<list_type_any2>\n"
+ " (?:\n"
+ " (?<list_type_unordered_star2>(?&list_unordered_star))\n"
+ " |\n"
+ " (?<list_type_unordered_minus2>(?&list_unordered_minus))\n"
+ " |\n"
+ " (?<list_type_unordered_plus2>(?&list_unordered_plus))\n"
+ " |\n"
+ " (?<list_type_ordered2>(?&list_ordered))\n"
+ " )\n"
+ " )\n"
+ " [ \\t]+\n"
+ " )\n"
+ " )\n"
+ ")\n"
+ "(?(DEFINE)\n"
+ " (?<list_unordered_star>\n"
+ " [\\*]\n"
+ " (?!\n"
+ " (?:\n"
+ " [ ]?[\\*][ ]?\n"
+ " ){2,}\n"
+ " )\n"
+ " )\n"
+ " (?<list_unordered_minus>\n"
+ " [\\-]\n"
+ " (?!\n"
+ " (?:\n"
+ " [ ]?[\\-][ ]?\n"
+ " ){2,}\n"
+ " )\n"
+ " )\n"
+ " (?<list_unordered_plus>[\\+])\n"
+ " (?<list_ordered>\\d+[\\.])\n"
+ ")";
final String string = "\n"
+ "* asterisk 1\n\n"
+ "* asterisk 2\n\n"
+ "* asterisk 3\n\n"
+ "* * *\n\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.COMMENTS);
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