我需要匹配大于5的失败次数。
string="""fail_count 7
fail_count 8
fail_count 9
fail count 7
fail_count 71
fail_count 23
"""
match = re.search(r'fail(\s|\_)count\s[5-9]', string)
if match:
print match.group()
我可以匹配到9,但如果我将范围增加到999,它不起作用。
发布于 2017-06-15 20:33:54
5-9或至少2位数字
'([5-9]|\d{2,})'
或者当它以5-9开始时匹配整个数字。
5-9,后跟任意数量的数字或至少2位
'([5-9]\d*|\d{2,})'
发布于 2017-06-15 20:40:33
https://stackoverflow.com/questions/44567572
复制相似问题