title: Python regular expression question mark operator not working?
body: <pre><code>import re
  str='abc defg'
  m1 = re.match(".*(def)?",str)
  m2 = re.match(".*(def)",str)
  print (m1.group(1),m2.group(1))
  </code></pre>
  
  <p>The output of the above is:</p>
  
  <blockquote>
    <p>(None, 'def')</p>
  </blockquote>
  
  <p>What is going on? Even with a non-greedy repetition operator, the optional capture group <code>(def)?</code> is not matched. </p>