title: C# Regular Expression to match letters, numbers and underscore
body: <p>I am trying to create a regular expression pattern in C#. The pattern can only allow for:</p>
  
  <ul>
  <li>letters</li>
  <li>numbers</li>
  <li>underscores</li>
  </ul>
  
  <p>So far I am having little luck (i'm not good at RegEx). Here is what I have tried thus far:</p>
  
  <pre><code>// Create the regular expression
  string pattern = @"\w+_";
  Regex regex = new Regex(pattern);
  
  // Compare a string against the regular expression
  return regex.IsMatch(stringToTest);
  </code></pre>