const 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.*/igm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^((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.*', 'igm')
const str = `qwarebatch_nc_20140714.TXT
AF32503.txt
CV4130214.TXT
CA5070515.TXT
CD4130115.txt
CC4130214.TXT
DI41102.txt
qwarebatch_dar_20150602.TXT
qwarebatch_darf_20150602.TXT
DC4130214.TXT
DL4160214.TXT
EC5070515.TXT
GF41102.txt
GP41102.TXT
qwarebatch_gru_intra_20150602.TXT
qwarebatch_lc_20150602.TXT
LO4130214.TXT
NT32503.txt
qwarebatch_nd_20150602.TXT
qwarebatch_ne_20150602.TXT
qwarebatch_nl_20150602.TXT
qwarebatch_ns_20150602.TXT
qwarebatch_ob_20150602.TXT
qwarebatch_pe_20140618.TXT
qwarebatch_pf_20150602.TXT
qwarebatch2_ptres_20150602.TXT
qwarebatch_ra_20150602.TXT`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions