In Python 2.6. it seems that the end-of-line markers $ and \Z are not compatible with group expressions. Example fo
import re re.findall("\w+[\s$]", "green pears")
returns
['green ']
(therefore $ does not work effectively). And using
re.findall("\w+[\s\Z]", "green pears")
leads to an error:
/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.""" --> 177 return _compile(pattern, flags).findall(string) 178 179 if sys.hexversion >= 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: --> 245 raise error, v # invalid expression 246 if len(_cache) >= _MAXCACHE: 247 _cache.clear() error: internal: unsupported set operator
Why does it work like this and how to get around?
python regex
Piotr migdal
source share