Q: Regex to disallow all symbols that windows doesnt allow in its file/folder names The symbols not allowed in filename or folder name in windows are \ / : * ? " < > |. I wrote a regex for it but not able to write regex to exclude " (double quotes).
Regex regex = new Regex(@"^[\\\/\:\*\?\'\<\>\|]+$");

Tried as below but it didnt work:
Regex regex = new Regex(@"^[\\\/\:\*\?\'\<\>\|&quot;]+$");

EDIT:
I am particularly looking for code with regex itself and hence its not a duplicate. 
Help is greatly appreciated. Thanks.

A: Instead of using Regex you could do something like this:
var invalidChars = new HashSet<char>(Path.GetInvalidFileNameChars());
var invalid = input.Any(chr => invalidChars.Contains(chr));


A: @Allrameest answer using Path.GetInvalidFileNameChars() is probably the one you should use. 
What I wanted to address is the fact that your regex is actually wrong or very ineffective (I don't know what exectly you wanted to do).
So, using:
var regex = new Regex(@"^[\\\/\:\*\?\'\<\>\|]+$");

mean you match a string which consists ONLY of "forbidden" characters (BTW, I think single quote ' is not invalid). Is it what you want? Don't think so. What you did is:


*

*^ start of the string

*[...]+ invalid characters only (at least once)

*$ end of the string


Maybe you wanted @"^[^...]+$" (hat used twice)?
Anyway, solution for your problem (with regex) is:


*

*don't use ^ or $ just try to find any of those and bomb out quickly

*in raw string (the one starting with @") you escape double quotes by doubling it.


So, the right regex is:
var regex = new Regex(@"[\\\/\:\*\?\""\<\>\|]");
if (regex.Match(filename).Success) {
    throw new ArgumentException("Bad filename");
}

Just find any and bomb out.

UPDATE by @JohnLBevan
var regex = new Regex(
    "[" + Regex.Escape(new string(Path.GetInvalidFileNameChars())) + "]");
if (regex.Match(filename).Success) {
    throw new ArgumentException("Bad filename");
}

(Not using string.Format(...) as this Regex should be static and precompiled anyway)
