const regex = /(-scaled|[_-]\d+x\d+)|@[2-6]\x(?=\.[a-z]{3,4}$)|\.[a-z]{3,4}.webp/igm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(-scaled|[_-]\\d+x\\d+)|@[2-6]\\x(?=\\.[a-z]{3,4}$)|\\.[a-z]{3,4}.webp', 'igm')
const str = `skip-IMG_7484-scaled.jpg
skip-IMG_7484.jpeg.webp
skip-IMG_7484.jpg.webp
skip-filename_500x383dddd.jpeg
skip-filename_500x383.jpeg
skip-filename-500x383.jpeg
skip-filename-500x383.jpg
skip-filename-500x383@2xddddd.jpg
skip-filename-500x383@2x.jpg
skip-filename-100x100@2x.jpg
skip-filename-1000x1000@3x.jpg
skip-filename-40x40@4x.jpg
keep-filename@2x copy.jpg
keep-filename@2x.jpg
keep-filename@3x.jpg
keep-filename@4x.jpg
keep-IMG_7484-normal-webp.webp
keep-IMG_7484-not-dot-jpg.webp
keep-IMG_7484.jpg
keep-f5229.jpg
keep-f5229as'ad"an.jpg`;
// 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