import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^((qwarebatch[0-9]?_((g?p(tres|[fse])|lc|ra|darf?|n[edlcs]|ob|gru_intra))_)|([AG]F|[EL]?[CO]([ACDV])?|D[CIL]|NT))[0-9]{5,8}\\.TXT.*";
final String string = "qwarebatch_nc_20140714.TXT\n"
+ "AF32503.txt\n"
+ "CV4130214.TXT\n"
+ "CA5070515.TXT\n"
+ "CD4130115.txt\n"
+ "CC4130214.TXT\n"
+ "DI41102.txt\n"
+ "qwarebatch_dar_20150602.TXT\n"
+ "qwarebatch_darf_20150602.TXT\n"
+ "DC4130214.TXT\n"
+ "DL4160214.TXT\n"
+ "EC5070515.TXT\n"
+ "GF41102.txt\n"
+ "GP41102.TXT\n"
+ "qwarebatch_gru_intra_20150602.TXT\n"
+ "qwarebatch_lc_20150602.TXT\n"
+ "LO4130214.TXT\n"
+ "NT32503.txt\n"
+ "qwarebatch_nd_20150602.TXT\n"
+ "qwarebatch_ne_20150602.TXT\n"
+ "qwarebatch_nl_20150602.TXT\n"
+ "qwarebatch_ns_20150602.TXT\n"
+ "qwarebatch_ob_20150602.TXT\n"
+ "qwarebatch_pe_20140618.TXT\n"
+ "qwarebatch_pf_20150602.TXT\n"
+ "qwarebatch2_ptres_20150602.TXT\n"
+ "qwarebatch_ra_20150602.TXT";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | 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