title: Python Regex - non-greedy match does not work
body: <p>I have a flat file with one C++ function name and part of its declaration like this:</p>
  
  <pre><code>virtual void NameSpace1::NameSpace2::ClassName1::function_name1(int arg1) const
  void function_name2
  void NameSpace2::NameSpace4::ClassName2::function_name3
  function_name4
  </code></pre>
  
  <p>I am trying to extract the function names alone by using this line:</p>
  
  <pre><code>fn_name = re.match(":(.*?)\(?", lines)
  </code></pre>
  
  <p>I can understand why <code>function_name2</code> and <code>function_name4</code> do not match (because there is no leading <code>:</code>. But I am seeing that even for <code>function_name1</code> and <code>function_name3</code>, it does not do non-greedy match. The output of <code>fn_name.group()</code> is</p>
  
  <pre><code>:NameSpace2::ClassName1::function_name1
  </code></pre>
  
  <p>I have three questions:</p>
  
  <ol>
  <li>I expected just the string "<code>function_name1</code>" to be extracted from line 1, but the non-greedy match does not seem to work. Why?</li>
  <li>Why is line 3 not being extracted?</li>
  <li>How do I get the function names from all the lines using a single regex?</li>
  </ol>
  
  <p>Please help.</p>