title: Python regex - why does end of string ($ and \Z) not work with group expressions?
body: <p>In Python 2.6. it seems that markers of the end of string <code>$</code> and <code>\Z</code> are not compatible with group expressions. Fo example</p>
  
  <pre><code>import re
  re.findall("\w+[\s$]", "green pears")
  </code></pre>
  
  <p>returns </p>
  
  <pre><code>['green ']
  </code></pre>
  
  <p>(so <code>$</code> effectively does not work). And using </p>
  
  <pre><code>re.findall("\w+[\s\Z]", "green pears")
  </code></pre>
  
  <p>results in an error:</p>
  
  <pre><code>/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/re.pyc in findall(pattern, string, flags)
      175 
      176     Empty matches are included in the result."""
  --&gt; 177     return _compile(pattern, flags).findall(string)
      178 
      179 if sys.hexversion &gt;= 0x02020000:
  
  /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/re.pyc in _compile(*key)
      243         p = sre_compile.compile(pattern, flags)
      244     except error, v:
  --&gt; 245         raise error, v # invalid expression
      246     if len(_cache) &gt;= _MAXCACHE:
      247         _cache.clear()
  
  error: internal: unsupported set operator
  </code></pre>
  
  <p><strong>Why does it work that way and how to go around?</strong></p>