我有这样的模式:
>>> pat = r'(?:.*)?(name)|nombres?'
当我测试时:
>>> import re
>>> re.search('nombre', pat).group()
>>> 'nombre'
>>> re.search('name', pat).group()
>>> 'name'
但是
>>> re.search('first_name', pat).group()
>>> *** AttributeError: 'NoneType' object has no attribute 'group'
如前所述,参数交换应为:
我还想说,在尝试提取组匹配之前,您可能需要检查模式是否实际匹配:
你的论点顺序不对。首先是模式
相关问题 更多 >
编程相关推荐