Q:

How do I escape characters c# refuses to escape?

Update
Before I see anymore "Just use a string literal!" take note I'm trying to escape the characters ()-_=+{[}|]. I think the regex engine doesn't know how to parse my expression correctly. A one point I had |] switched around to be ]| and found my regex was passing everything as long as it had a lower, upper, and a numeric. Now its failing everything. The answer I'm looking for will explain what's wrong with my regex.

I have this regex I'm using for passwords
^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[~`!@#$%^&*()-_=+{[}|]:\";'<>?,./\\])[^\r\n\t\f ]{8,16}$

Here's the javascript equivalent as a literal:
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[~`!@#$%^&*()\-_=+{[}\]|:";'<>?,.\/\\])[^\r\n\t\f ]{8,16}$/

The javascript expression works fine. At least 1 lowercase, 1 uppercase, 1 number, 1 special character, and have it be between 8 and 16 characters. 
My problem is I can't figure out how I'm suppose to escape the grouping characters in the group
(?=.*[~`!@#$%^&*()-_=+{[}|]:\";'<>?,./\\])

Specifically, the {[}|] portion. If I try \[ it gives an error, yet the good ole MSDN says otherwise.
I'm using it in a validation attribute for the password field
[RegularExpression("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[~`!@#$%^&*()-_=+{[}|]:\";'<>?,./\\])[^\r\n\t\f ]{8,16}$", ErrorMessage = "Password must meet all specified criteria.")]

A:

The answer I'm looking for will explain what's wrong with my regex

Here's your regex:
[RegularExpression(
  "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[~`!@#$%^&*()-_=+{[}|]:\";'<>?,./\\])[^\r\n\t\f ]{8,16}$"

This is wrong. You wish to know why it is wrong. Let's break it down.
First of all, this is a C# string literal.  What characters does it actually represent? Remember, C# string literals contain escape sequences. The characters in this thing are:
^ ( ? = . * [ a - z ] ) ( ? = . * [ A - Z ] ) ( ? = . * 
\    -- this is the character represented by \\
d ) ( ? = . * [ ~ ` ! @ # $ % ^ & * ( ) - _ = + { [ } | ] :
"    -- this is the character represented by \"
; ' < > ? , . / 
\  -- this is the character represented by \\
] ) [ ^ 
<carriage return>   -- represented by \r
<newline>           -- represented by \n
<tabstop>           -- represented by \t
<feed>              -- represented by \f
<space>
] { 8 , 1 6 } $ 

Those are the characters in your string. Do they represent the regular expression you want?  Plainly not. This string contains the regular expression (I'll add newlines between the subexpressions for clarity):
^(?=.*[a-z])  -- right
 (?=.*[A-Z])  -- right
 (?=.*\d)     -- right
 (?=.*[~`!@#$%^&*()-_=+{[}|]:";'<>?,./\]) -- NOPE
 [^<carriage return><newline><tabstop><feed><space>] -- seems dodgy
 {8,16}$ -- right

The bit marked NOPE is plainly wrong.  What string do you want it to be?  You want it to be this set of characters:
 (?=.*[~`!@#$%^&*()\-_=+{[}\]|:";'<>?,./\\])

But it is not that set of characters. Now do you understand what you've done wrong?
In a C# regular string literal that set of characters is represented by:
 "(?=.*[~`!@#$%^&*()\\-_=+{[}\\]|:\";'<>?,./\\\\])"

In a C# verbatim string literal that set of characters is represented by:
 @"(?=.*[~`!@#$%^&*()\-_=+{[}\]|:"";'<>?,./\\])"

Note that the verbatim literal is, well, verbatim, except for the double-double quote. Hence the name.  Use verbatim literals when building regular expressions in C#.
Also, in the future you should solve this sort of problem by trying to solve small sub-problems on your own.  Had you tried writing a regular expression that matched a single [, then you would have found your problem a lot sooner; had you been unable to do so, then your SO question about how to do so would have been a lot easier to answer. Regular expressions are compositional; break the problem down into smaller problems, test each solution, and then combine them.  Had you proceeded like this:
const string Lowercase = "(?=.*[a-z])";
const string Uppercase = "(?=.*[A-Z])";
const string Digits = "(?=.*\\d)";
const string Symbols = "(?=.*[~`!@#$%^&*()-_=+{[}|]:\";'<>?,./\\])"; // Wrong!
const string NoWhitespace = "[^\r\n\t\f ]"; // Dodgy!
const string Password = "^" + Lowercase + Uppercase + Digits + Symbols + NoWhitespace + "{8,16}$";

then you would have code that is ready-made for unit testing.  When the password regexp failed, you could have tested each part of it independently and figured out what was going wrong, you could have tried replacing "Symbols" with an expression that just matches [(, say, and debugged that. (And notice also how much more self-documenting, maintainable and clear my version is. It still looks like modem line noise, but at least it is self-explanatory modem line noise.)

