Python正则表达式-为什么字符串结尾($和\ Z)无法与组表达式一起使用?
发布于 2021-01-29 17:45:51
在Python 2.6中。似乎字符串末尾的那个标记$
和\Z
不符合组表达式兼容。佛的例子
import re
re.findall("\w+[\s$]", "green pears")
退货
['green ']
(因此$
实际上无效)。并使用
re.findall("\w+[\s\Z]", "green pears")
导致错误:
/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
为什么这样工作以及如何解决?
关注者
0
被浏览
44
1 个回答