title: Optional Capture Group Not Capturing
body: <pre><code>&lt;tr&gt;&lt;td align=right&gt;Name:&lt;/td&gt;&lt;td align=left&gt;&lt;b&gt;&lt;font color=black&gt;Nathan&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td align=right&gt;Extension:&lt;/td&gt;&lt;td align=left&gt;&lt;b&gt;222&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
  </code></pre>
  
  <p>I have the above <strike>HTML</strike> glob of text (can't be changed) and I'd like a regular expression that returns 3 capturing groups, the label <code>(Name|Extension)</code> the font color <code>(black|red)</code> and the data <code>(\w+)</code>.</p>
  
  <p>I'm having some trouble returning capture group 2, the font color. As you can see, it's not present on the "Extension" row of the table, so I've made the capture group optional. When I do that, it's not matching at all on the first row. I've tried fiddling a lot with trial and error of a bunch of different combinations of quantifiers, but I still can't get the result I'm looking for.</p>
  
  <p>Here's the pattern I have so far: <code>(Name|Extension):.*?(?:&lt;font color=(black|red)&gt;)?.*?&gt;(\w+)</code></p>
  
  <p>I believe the <code>.*?</code> is consuming what would be the optional capture group and only matching the 1st and 3rd group. If someone could explain to me where I've gone wrong, that would be great.</p>
  
  <p>Edit: As someone who is trying to learn more about regular expressions, I would appreciate it if people could interpret the data I have above as immutable text rather than HTML.</p>