title: Count number of occurences of each string using regex
body: <p>Given a pattern like this</p>
  
  <pre><code>pattern = re.compile(r'\b(A|B|C)\b')
  </code></pre>
  
  <p>And a <code>huge_string</code> I would like to replace every substring matching the pattern with a string <code>D</code> and find the number of occurences for each string <code>A</code>, <code>B</code> and <code>C</code>. What is the most feasible approach?</p>
  
  <p>One way is to split the pattern to 3 patterns for each string and then use subn</p>
  
  <pre><code>pattern_a = re.compile(r'\bA\b')
  pattern_b = re.compile(r'\bB\b')
  pattern_c = re.compile(r'\bC\b')
  huge_string, no_a = re.subn(pattern_a, D, huge_string)
  huge_string, no_b = re.subn(pattern_b, D, huge_string)
  huge_string, no_c = re.subn(pattern_c, D, huge_string)
  </code></pre>
  
  <p>But it requires 3 passes through the huge_string. Is there a better way?</p>