您的位置:首页 > 编程语言 > Python开发

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

2016-07-12 08:24 666 查看
#牧飞(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>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 正则表达式