const regex = new RegExp('SMR_.*_(.*)_GRID_(?P<Model>[a-zA-Z]+)_.*', 'gm')
const str = `RV_Exp_CX_GRID_08OCT18.dat
RV_Exp_JT_GRID_07NOV18.dat
RV_Exp_OPEL_WB_GRID_21NOV18.dat
RV_Ref_U_GRID_07NOV18.dat
SMR_Exp_CX_GRID_D_11OCT18txt
SMR_Exp_CX_GRID_E_30JUL18txt
SMR_Exp_CX_GRID_JS_07AUG18txt
SMR_Exp_CX_GRID_JT_17SEP18txt
SMR_Exp_GRID_D_07NOV18txt
SMR_Exp_GRID_E_05OCT18txt
SMR_Exp_GRID_JS_08JAN19txt
SMR_Exp_GRID_JT_07NOV18txt
SMR_Ref_GRID_D_07NOV18txt
SMR_Ref_GRID_E_05OCT18txt
SMR_Ref_GRID_JS_08JAN19txt
SMR_Ref_GRID_JT_07NOV18txt
SMR_WB_Exp_GRID_D_14NOV18txt
SMR_WB_Exp_GRID_JS_20FEB19txt
SMR_WB_Exp_GRID_JT_14NOV18txt`;
// 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