title: Regex to extract CSS classnames and IDs
body: <p>I have some CSS and I'm looking to create a list of all the class names and identifiers. This is what I have:</p>
  
  <pre><code>var TheList = new List&lt;string&gt;();
  var Test2 = Regex.Matches(TheCSS, ".-?[_a-zA-Z]+[_a-zA-Z0-9-]*(?=[^}]*\\{)");
  
  foreach(Match m in Test2)
  {
      TheList.Add(m.Value);
  }
  </code></pre>
  
  <p>The problem is that there are some unwanted elements:</p>
  
  <pre><code>body
  :hover
  select
  input
  label
  [for
  input
  [type
  'radio
  </code></pre>
  
  <p>I've tried with several regex expressions that I've found online; this one is the closest but it's not perfect yet. Basically, it needs to include only elements that begin with <code>#</code> and <code>.</code> so as to avoid <code>body</code> and <code>[type</code> and then not include pseudo-selectors like <code>:hover</code></p>
  
  <p>What do I need to change in the regex to make it work?</p>
  
  <p>Thanks.</p>