01密码强度检查_python篇
需求:
解决方法(本人写的):
写一个与需求相关的正则表达式,断言是否匹配,不匹配返回false,匹配返回ture
代码参考如下
import re # 断言 # 成功的话,就输出这句话
|
其他解决方法:
参考他人的,这个正则表达式没看懂,有理解的同学麻烦留言一下
import re
def checkio(data): # (?=) is positive lookahead. Use this construction to make sure the enclosed pattern exists return bool(re.search(r'^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{10,}$', data))
if __name__ == '__main__': # These "asserts" using only for self-checking and not necessary for # auto-testing assert checkio('A1213pokl') == False, "1st example" assert checkio('bAse730onE4') == True, "2nd example" assert checkio('asasasasasasasaas') == False, "3rd example" assert checkio('QWERTYqwerty') == False, "4th example" assert checkio('123456123456') == False, "5th example" assert checkio('QwErTy911poqqqq') == True, "6th example"
|