使用python来做正则表达式:
import re
txt = "2343 33 89 2 sdf"
#Check if the string has any two-digit numbers, from 00 to 59:
x = re.findall("[0-5][0-9]", txt)
print('numbers from 00 to 59 结果: ',x)
if x:
print("Yes, there is at least one match!")
else:
print("No match")
txt_new = "234 33 89 2 sdf"
#Check if the string has any two-digit numbers, from 00 to 59:
y = re.findall('[0-5][0-9]', txt_new)
print('numbers from 00 to 59 结果:',y)
[0-5][0-9]意思: Returns a match for any two-digit numbers from 00 and 59
结果如下:
解释一下结果:由于代码中用了[ ][ ]来做范围。比如[0-5]对应的是十位数所取的数字的范围为0-5,[0-9] 表示个位数的数字范围为0-9.
如果觉得不错,就点赞或者关注或者留言~
谢谢~