正则匹配总是报错

ss='北京奇谈文化有限公司'
print(re.findall('(.*?有限公司){5,20}',ss)[0])
Traceback (most recent call last):
File "<input>", line 1, in <module>
IndexError: list index out of range
print(re.findall('(.*?有限公司){5,20}',ss)[0])
Traceback (most recent call last):
File "<input>", line 1, in <module>
IndexError: list index out of range
print(re.findall('(.*?有限公司)',ss)[0])
北京责任有限公司
print(re.findall('(.*?有限公司){5,20}',ss)[0])
Traceback (most recent call last):
File "<input>", line 1, in <module>
IndexError: list index out of range
为啥我加上限制长度的总是报错呢?匹配不到

阅读 1.4k
1 个回答

{n, m}:m、n都是非负数,最少匹配n次,最多匹配m次。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题