Python中re.compile遇到only supports 100 named groups的问题

来源:互联网 发布:爰淘宝 编辑:程序博客网 时间:2024/06/04 22:24

#牧飞(mufei)

#Python中re.compile遇到only supports 100 named groups的问题

今天要Python弄个正则表达式来匹配, 发现有个"AssertionError: sorry, but this version only supports 100 named groups"错误.


>>> import re
>>> re.compile('(.moofei)'*100)
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Python27\lib\re.py", line 194, in compile
    return _compile(pattern, flags)
  File "C:\Python27\lib\re.py", line 249, in _compile
    p = sre_compile.compile(pattern, flags)
  File "C:\Python27\lib\sre_compile.py", line 583, in compile
    "sorry, but this version only supports 100 named groups"
AssertionError: sorry, but this version only supports 100 named groups


网上搜了一下解决办法都是用for循环来匹配来解决.

我想了一下不用命名groups也可以解决问题, 在.前面加个?:完美解决问题.

>>> re.compile('(?:.mufei)'*100)
<_sre.SRE_Pattern object at 0x0000000004AAEAA0>


微笑





1 0