using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^(?!^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$)[^\x00-\x1F<>:\""\/\\|?*]*[^\x00-\x1F<>:\""\/\\|?*. ]$";
string input = @"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
";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx