title: Python regex: How to specify an optional match (for potentially empty sub expression)?
body: <p>I need to match the following sets of input:</p>
  
  <pre><code>foo_abc_bar  
  foo_bar
  </code></pre>
  
  <p>and get "abc" or an empty string as the result.</p>
  
  <p>So this is the regular expression I wrote:</p>
  
  <p><code>r'foo_(abc|)[_|]bar'</code></p>
  
  <p>But for some reason, this does not match with the second string that I have given.</p>
  
  <p>On further inspection, I found that <code>[_|]</code> does not match an empty string.</p>
  
  <p>So, how do I solve this problem?</p>