确保传入的口令字符串是强口令
强口令:长度不少于8字符,同时包含大小写,至少一位是数字;
第一次尝试:
import pyperclip,re
spamRegex=re.compile(r'[((a-z)+)((A-Z)+)((0-9)+)]{3,}')#初始的想法是:至少包含“一个大写一个小写一个数字”(“”里的内容用👔代替),👔包含至少三个字符(大、小、数),然后👔匹配至少3次(即9字符)
text=str(pyperclip.paste())
matches=spamRegex.findall(text)
if matches:
print(matches)
else:
print('No number found.')
这次尝试我全选程序内容,作为样本,输出如下:
['import', 'pyperclip', 'spamRegex', 'compile(r', '((a', 'z)+)((A', 'Z)+)((0', '9)+)', 'text', 'str(pyperclip', 'paste())', 'matches', 'spamRegex', 'findall(text)', 'matches', 'print(matches)', 'else', 'print(', 'number', 'found']
这里是成功输出了,但是输出的和我们想要的还是不一样,证明程序逻辑没有问题,但正则表达式有误,还需要进一步修改:
**
*这里我先编一个测试文本:
**
anda4lgrnslfdlisj,4546336etr ,
@ lnuigiagisdhngrwo,AFA5sdfgdg;
afdAFD, asfADF5fhdhf, afdD68,5huadsDSD,dasnu3ASD,SD3
(测试文本修改过,下面输出程序可能有变动)
第二次尝试:
import pyperclip,re
spamRegex=re.