我正在尝试使用正则表达式来确保传递的密码字符串很强的强密码检测任务。强密码定义为长度至少为八个字符,同时包含大写和小写字符以及至少一位数字的密码。我们需要针对多个正则表达式模式测试字符串,以验证其强度。
这是我提议的相同代码:
import re
def password_detect(exp):
if len(exp) >= 8:
passRegex = re.compile('r[(a-z)+(A-Z)+(0-9)+]')
mo = passRegex.search(exp)
if mo.group() != None:
print("Password is strong")
else:
print("Password is not strong")
else:
print("Password length is not strong")
它返回此回溯:
Traceback (most recent call last):
File "<ipython-input-245-4202435a0efb>", line 1, in <module>
password_detect('oldG2020')
File "<ipython-input-243-39585a6ade11>", line 5, in password_detect
if mo.group() != None:
AttributeError: 'NoneType' object has no attribute 'group'
返回哪个NoneType?它似乎遵循规则。谢谢。