以下是代码:
import re
string = "02:222222"
if re.match(r'[a-fA-F0-9]+[a-fA-F0-9]+:+[a-fA-F0-9]+[a-fA-F0-9]+$',string):
print "pass"
else:
print "fail"
Run Code Online (Sandbox Code Playgroud)
上面的代码是打印"通过"
我的预期输出应该是"失败"
以下是几个例子:
string = 00:20
expected output: pass
string = 00:202
expected ouput: fail
string = 00:2z
expected output: fail
string = 000:2
expected ouput: fail
Run Code Online (Sandbox Code Playgroud)