const regex = /^(?:.*[\/\\])?(?<FileNameWithoutExtension>.*)\.(.*)$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?:.*[\\\/\\\\])?(?<FileNameWithoutExtension>.*)\\.(.*)$', 'gm')
const str = `Taylor Swift - New Romantics.m4a
YT/Subto2mp3/Taylor Swift - New Terribly Romantics.m4a
Grow - Conan Blue (Official Video) has already been recorded in archive.m4a
PowerOptim Iol/Techno/(Official Video) Blue Burrow was already been recorded in archive - Bak.wm4
/Great Bun/Output Files/çè/Grow - Conan DARK (Official AUDIO) has already been recorded in archive.m4b
Matter Oil_9999.zip
Qpl\$-pol.hrlp/perm.ui.pol/i op/doesn't matter.mp4
Small Laser4.m4a
manicur pliu/love is in the a°°_II+?§@R.txt
^Level09\\\\Power Pol\\energy.m4a
lollller_blllade 1987 (c)/super €/music_piece_.mp3
\\.\\.\$./../../loli( u1990) _98.lop.pl/fil l/fill2asm.aile.asm.gz.zip
/Taylor Swift - New Romantics._m4a
\\\$/Subto2/mp3/Taylor Swift -&- New Romantics.m4a
/Grow - Conan Gray (Official Video) has already been recorded in archive.m4a
C:\\PowerOptim Iol/Grow - The New Gray (Official Video) has been recorded [<1999>.wm4
/Great Bun/Output Files/çè/Grow - WiLlL(O)W Gray "unofficial" video has not been recorded in archive.m4b
/Matter Oil_9999.zip
file:///Qpl\$-pol.hrlp/perm.ui.pol/i op/matter.mp4
/£¥«^6<4>à_»Laser4 \`\`[12{2%}32]deg\`‘.webm
manicur pliu/great.power.great.responsibility?.gz.tar.zip
./poi kiol/greater.power.greater.responsibility!.gz.tar.zip
^Level09\\Power Pol\\energy.m4a
lollller_blllade 1987 (c)/super €/music_piece_.mp3
/The 'great' solitude of zorro #12/the 退ellent urge_for.mo.tar.gz
`;
// 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