$re = '/^(?!^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$)[^\x00-\x1F<>:\"\/\\\\|?*]*[^\x00-\x1F<>:\"\/\\\\|?*. ]$/m';
$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
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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 PHP, please visit: http://php.net/manual/en/ref.pcre.php