import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "((?<=Description\\:[\\r\\n|\\r|\\n])(\\d+\\.|\\-)\\ (?P<desc>(.+)\\.))|((?<=\\.[\\r\\n|\\r|\\n])((\\d+\\.|\\-)\\ (?P<desc2>(.+)\\.))(?=[\\r\\n|\\r|\\n](\\d+\\.|\\-)|[\\r\\n|\\r|\\n]*Reference))";
final String string = "[FIX]: Fix bad wiring on plane 334, 335,\n"
+ "and 336. Remove decorator for 446.\n\n"
+ "Description:\n"
+ "1. sadsadad.\n"
+ "2. kjadhkahsdkahdjakdskashdkasjdsahdkhadhkasdhjkhaskd.\n"
+ "3. djasdasdasdadkajdsjaskldjalkdjalsjdlajsdlkjasdlas.\n\n"
+ "Reference: #232\n\n"
+ "([\\d]+\\. )(.*?)(?=([\\d]+\\.)|($))\n\n"
+ "((?<=Description\\:[\\r\\n|\\r|\\n])(\\d+\\.|\\-)\\ (?P<desc>(.+)\\.))|((?<=\\.[\\r\\n|\\r|\\n])((\\d+\\.|\\-)\\ (?P<desc2>(.+)\\.))(?=[\\r\\n|\\r|\\n](\\d+\\.|\\-)|[\\r\\n|\\r|\\n]*Reference))";
final Pattern pattern = Pattern.compile(regex);
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