title: Python regular expression not matching end of line
body: <p>I'm trying to match a C/C++ function definition using a fairly complex regular expression.  I've found a case where it's not working and I'm trying to understand why.  Here is the input string which does not match:</p>
  
  <pre><code>   void Dump(const char * itemName, ofstream &amp; os)
  </code></pre>
  
  <p>which clearly is a valid C++ method declaration.  Here is the RE:</p>
  
  <pre><code>   ^[^=+-|#]*?([\w&lt;&gt;]+\s+(?!if|for|switch|while|catch|return)\w+)\s*\([^;=+-|]*$
  </code></pre>
  
  <p>This basically tries to distinguish between other C syntax which looks like a method declaration, i.e. which has words followed by paraentheses.  </p>
  
  <p>Using the very useful Python regular expression debugger (http://www.pythonregex.com/) I've narrowed it down to the trailing "$" - if I remove the trailing $ in the regular expression, it matches the method signature above; if I leave in the $, it doesn't.  There must be some idiosyncracy of Python RE's that is eluding me here.  Thanks.</p>