const regex = /[\w\+\-]+\.\w+\.(?<EPOCH>\d+)(?<AV>\.av)?\.mat/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('[\\w\\+\\-]+\\.\\w+\\.(?<EPOCH>\\d+)(?<AV>\\.av)?\\.mat', 'g')
const str = `AvAnalysisTill20Kepoch_onlyW.png
Program.30_07_2017_14_03_31.1.json
Program.30_07_2017_14_03_31.1.mat
Program.30_07_2017_14_03_31.10002.mat
Program.30_07_2017_14_03_31.10005.mat
Program.30_07_2017_14_03_31.10005.av.mat
Program.30_07_2017_14_03_31.10005.mat
Program.30_07_2017_14_03_31.10008.mat
Program.30_07_2017_14_03_31.10011.mat
Program.30_07_2017_14_03_31.10014.mat
Program.30_07_2017_14_03_31.10017.mat
Program.30_07_2017_14_03_31.1002.mat
Program.30_07_2017_14_03_31.10020.mat
Program.30_07_2017_14_03_31.10023.mat
Program.30_07_2017_14_03_31.10026.mat
Program.30_07_2017_14_03_31.10029.mat
Program.30_07_2017_14_03_31.10032.mat
Program.30_07_2017_14_03_31.10035.mat
Program.30_07_2017_14_03_31.10038.mat
Program.30_07_2017_14_03_31.10041.mat
Program.30_07_2017_14_03_31.10044.mat
Program.30_07_2017_14_03_31.10047.mat
Program.30_07_2017_14_03_31.1005.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19950.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19953.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19956.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19959.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19962.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19965.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19968.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19971.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19974.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19977.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19980.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19983.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19986.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19989.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19992.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19995.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19998.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.20000.mat
`;
// 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