const regex = /\/[A-Z]?[a-z]{1,3}[0-9]?\.exe$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\\/[A-Z]?[a-z]{1,3}[0-9]?\\.exe$', 'gm')
const str = `hxxp://mnmassagetherapy[.]com/wp-content/uploads/2016/04/lib.exe
hxxp://seed-bc[.]com/juop4/plwr/mklo/rbn/jan2.exe
hxxp://15.204.49[.]148/files/Had.exe
hxxp://hugo.topteamlife[.]com/order/tuc5.exe`;
// 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