python实践项目六:正则表达式-强口令
2019-07-05 17:49
281 查看
描述:写一个函数,它使用正则表达式,确保传入的口令字符串是强口令。强口令的定义是:长度不少于8 个字符, 同时包含大写和小写字符, 至少有一位数字。
代码:
#!/usr/bin/python # -*- coding: UTF-8 -*- # 写一个函数,它使用正则表达式,确保传入的口令字符串是强口令。强口令的定义是:长度不少于8 个字符, # 同时包含大写和小写字符, 至少有一位数字。你可能需要用多个正则表达式来测试该字符串, 以保证它的强度。 import re,pyperclip def detection(text): if (len(text)<8): return False number1=re.compile(r'\d+') #创建一个正则表达式:任意数字,r表示不转义,+表示可匹配多个 if number1.search(text)==None: return False number2=re.compile(r'[A-Z]+')#任意大写字母 if number2.search(text)==None: return False number3 = re.compile(r'[a-z]+') # 任意小写字母 if number3.search(text) == None: return False return True # text=str(pyperclip.paste())#从剪贴板复制命令 text=raw_input("Get the password that you want to set:\n") if detection(text): print "The password is the strong password." else: print "Waring:the password is not the strong password!"
运行结果:
示例1:
示例2:
示例3:
相关文章推荐
- python实践项目七:正则表达式版本的strip()函数
- Linux企业级项目实践之网络爬虫(14)——使用正则表达式抽取HTML正文和URL
- Linux企业级项目实践之网络爬虫(14)——使用正则表达式抽取HTML正文和URL
- Python爬虫实践(七):正则表达式(2) re模块的使用
- [项目实训]Python正则表达式和Re库
- python常用正则表达式以及实践
- python爬虫学习实践(一):requests库和正则表达式之淘宝爬虫实战
- Python爬虫实践(六):正则表达式(1)
- Python爬虫实践(八):正则表达式re模块(2)
- Python 正则表达式匹配INI Section头
- python(4)正则表达式
- PHP核心技术与最佳实践之正则表达式匹配规则
- Python 爬虫学习笔记之正则表达式
- Python字符编码与正则表达式指南
- python正则表达式使用
- Python 网络爬虫-正则表达式、BeautifulSoup、lxml三种提取方法
- Python3 正则表达式的元字符的解释
- 正则表达式及python re模块
- Python 正则表达式
- Python正则表达式学习小结