title: Delete substring not matching regex in Python
body: <p>I have a string like: </p>
  
  <pre><code>'class="a", class="b", class="ab", class="body", class="etc"'
  </code></pre>
  
  <p>I want to delete everything except <code>class="a"</code> and <code>class="b"</code>.</p>
  
  <p>How can I do it? I think the problem is easy but I'm stuck.</p>
  
  <p>Here is some one of my attempts but it didn't solve my problem:</p>
  
  <pre><code>re.sub(r'class="also"|class="etc"', '', a)
  </code></pre>
  
  <p>My string is a very long HTML code with a lot of classes and I want to only keep two of them and drop all the others.
  Some times its good to make a break. I found solution for me with bleach</p>
  
  <pre><code>def filter_class(name, value):
      if name == 'class' and value == 'aaa':
          return True
  
  attrs = {
      'div': filter_class,
  }
  bleach.clean(html, tags=('div'), attributes=attrs, strip_comments=True)
  </code></pre>