const regex = new RegExp('^(?!^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$)[^\\x00-\\x1F<>:\\"\\/\\\\|?*]*[^\\x00-\\x1F<>:\\"\\/\\\\|?*. ]$', 'gm')
const str = `hallo men name ist bernd.txt
< (less than)
> (greater than).txt.
(greater-than).txt
(greater-than).txt.
: (colon - sometimes works, but is actually NTFS Alternate Data Streams)
" (double quote)
/ (forward slash)
\\ (backslash)
| (vertical bar or pipe)
? (question mark)
Loldusche (Lécuseß Adalb@mmals).jpeg
* (asterisk)
esel-ekay.txt
CON
CON, PRN, AUX, NUL
CON, PRN, AUX, NUL
COM1
COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9
LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9
LPT1
LPTx
`;
// 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