title: RegEx to tell if a string does not contain a specific character
body: <p>Easy question this time.</p>
  
  <p>I'm trying to test whether or not a string does not contain a character using regular expressions.  I thought the expression was of the form "[^<em>x</em>]" where <em>x</em> is the character that you don't want to appear, but that doesn't seem to be working.</p>
  
  <p>For example,</p>
  
  <pre><code>Regex.IsMatch("103","[^0]")
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Regex.IsMatch("103&amp;","[^&amp;]")
  </code></pre>
  
  <p>both return true (I would expect false).</p>
  
  <p>I started using <code>"[^&amp;]"</code> and thought maybe the &amp; needed to be escaped as \&amp;, but it didn't seem to make a difference.</p>
  
  <p>Ideas?  I assume it's something small.</p>
  
  <p>Also, I'm using .NET, so keep that in mind.</p>
  
  <p>Edit1:</p>
  
  <p>I found <a href="https://stackoverflow.com/questions/42990/regex-to-match-against-something-that-is-not-a-specific-substring">this</a>, but it doesn't seem to answer the issue I'm having.</p>
  
  <p>Edit2:</p>
  
  <p>I wanted to respond to <a href="https://stackoverflow.com/questions/198781/regex-to-tell-if-a-string-does-not-contain-a-specific-character#198793">Kevin</a> and <a href="https://stackoverflow.com/questions/198781/regex-to-tell-if-a-string-does-not-contain-a-specific-character#198796">Joel</a>'s suggestions.  These suggestions would indeed be faster, but they don't accomplish the flexibility I need in this case, so if you found this question through search, definitely look to see if their answers will fit your needs.  In my case, the regular expression is getting passed in to a DataTable validation method that loops through each row and verifies that the contents of that row in a specific column matches the RegEx that is getting passed in.  Since I'll be reusing this method for several other DataTables that are being validated, I wanted to:</p>
  
  <ol>
  <li>Use Regex to enable the widest range of validations, and</li>
  <li>Always look for a positive match (i.e. instead of using !Regex.IsMatch(cell, regexvariable), I wanted to rely on always being able to use Regex.IsMatch(cell, regexvariable) since the majority of DataTables invoking this method will be using the positive match instead of the negative.</li>
  </ol>
  
  <p>Hopefully that helps.</p>