title: .Net Regex.Escape not working properly?
body: <p>I am trying to write a regular expression which takes a string of character and builds them into an expression as a range. I use Regex.Escape (.net 3.5) to sanitize these strings so that there shouldn't be any control characters left. But it seems as though the Escape method isn't working as expected and won't escape closing <code>}</code> or <code>]</code> characters. Shouldn't it be escaping these? Here is an example of what I am doing:</p>
  
  <pre><code>string test = @"sdfz346gv][)(}{&gt;&lt;";
  string pattern = "[" + Regex.Escape(test) + "]+";
  string input = "ffff{444}g";
  
  if (Regex.IsMatch(input, pattern))
  {
      Console.WriteLine("Matched");
  }
  else
  {
      Console.WriteLine("Not Matched");
  }
  </code></pre>
  
  <p>The <code>pattern</code> string seems to have the value <code>[sdfz346gv]\[\)\(}\{&gt;&lt;]+</code> and won't match <code>ffff{444}g</code> but as far as I'm concerned it should look like this <code>[sdfz346gv\]\[\)\(\}\{&gt;&lt;]+</code> which is an expression that performs a differently and will match <code>ffff{444}g</code>. I could just replace <code>}</code> and <code>]</code> characters with <code>\}</code> and <code>\]</code> but are there any other characters that don't get escaped by this escape method? Can I rely on it?</p>