import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<=Due Date )\\d{2}.[A-Z]{3}.\\d{4}|(?<=Terms )(\\S.+)|(?<=Terms\\n\\n\\d{2}.[A-Z]{3}.\\d{4}.)(\\d{2}.[A-Z]{3}.\\d{4})|(?<=Terms\\n\\n\\d{2}.[A-Z]{3}.\\d{4}.\\d{2}.[A-Z]{3}.\\d{4}.)(\\S.+)|(?<=\\d{2}.[A-Z]{3}.\\d{4}.)(\\d{2}.[A-Z]{3}.\\d{4}.)|(?<=\\d{2}.[A-Z]{3}.\\d{4}.\\d{2}.[A-Z]{3}.\\d{4}.)(\\S.+)";
final String string = "Invoice Number Invoice Date Due Date Terms\n\n"
+ "Remit To 100 USD Remit To 200\n\n"
+ "XI 3849 30 MAR 2017 29 APR 2017 Within 30 days Due net\n\n"
+ "Sample 2)\n\n"
+ "Due Date 30 SEP 2017\n"
+ "Terms Within 30 days Due net\n\n"
+ "Sample 3)\n\n"
+ "Invoice Date Due Date Terms\n\n"
+ "30 MAR 2018 29 APR 2018 Not more than 30 days";
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