import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^SageAccts Company Name 2018-[01][0-9]-([0-3][0-9]) [0-2][0-9]-[0-5][0-9]-[0-5][0-9]$";
final String string = "SageAccts Company Name 2018-06-01 00-00-10\n"
+ "SageAccts Company Name 2018-06-02 00-00-10\n"
+ "SageAccts Company Name 2018-06-03 00-00-10\n"
+ "SageAccts Company Name 2018-06-04 00-00-10\n"
+ "SageAccts Company Name 2018-06-05 00-00-10\n"
+ "SageAccts Company Name 2018-06-06 00-00-10\n"
+ "SageAccts Company Name 2018-06-07 00-00-10\n"
+ "SageAccts Company Name 2018-06-08 00-00-10\n"
+ "SageAccts Company Name 2018-06-09 00-00-10\n"
+ "SageAccts Company Name 2018-06-10 00-00-10\n"
+ "SageAccts Company Name 2018-06-11 00-00-10\n"
+ "SageAccts Company Name 2018-06-12 00-00-10\n"
+ "SageAccts Company Name 2018-06-13 00-00-10\n"
+ "SageAccts Company Name 2018-06-14 00-00-10\n"
+ "SageAccts Company Name 2018-06-15 00-00-10\n"
+ "SageAccts Company Name 2018-06-16 00-00-10\n"
+ "SageAccts Company Name 2018-06-17 00-00-10\n"
+ "SageAccts Company Name 2018-06-18 00-00-10\n"
+ "SageAccts Company Name 2018-06-19 00-00-10\n"
+ "SageAccts Company Name 2018-06-20 00-00-10\n"
+ "SageAccts Company Name 2018-06-21 00-00-10\n"
+ "SageAccts Company Name 2018-06-22 00-00-10\n"
+ "SageAccts Company Name 2018-06-23 00-00-10\n"
+ "SageAccts Company Name 2018-06-24 00-00-10\n"
+ "SageAccts Company Name 2018-06-25 00-00-10\n"
+ "SageAccts Company Name 2018-06-26 00-00-10\n"
+ "SageAccts Company Name 2018-06-27 00-00-10\n"
+ "SageAccts Company Name 2018-06-28 00-00-10\n"
+ "SageAccts Company Name 2018-06-29 00-00-10\n"
+ "SageAccts Company Name 2018-06-30 00-00-10";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
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