#!/usr/bin/env python3.5
#coding:utf-8
import re # 7.18.1 # 强口令检测
# 写一个函数,使用正则表达式,确保传入的口令字符串是强口令
# 长度不少于8个字符,同时包含大小写,至少有1个数字 pw = input("请输入口令:")
def checkpw(passwd):
plen = len(passwd)
print(plen)
chpw1 = re.compile(r'.*[A-Z]+.*')
chpw2 = re.compile(r'.*[a-z]+.*')
chpw3 = re.compile(r'.*\d{1,}.*')
chresult1 = chpw1.search(passwd)
print("匹配大写字符",chresult1)
chresult2 = chpw2.search(passwd)
print("匹配小写字符",chresult2)
chresult3 = chpw3.search(passwd)
print("匹配至少1个数字",chresult3)
if (plen >= 8) and (chresult1 != None) and (chresult2 != None) and (chresult3 != None):
print("你的密码符合要求")
else:
print("你的密码不符合要求") checkpw(pw) #7.18.2
# 写一个函数,它接受一个字符串,做的事情和strip()一样
# 如果只传入了要去除的字符串,没有其它参数,那么就去除首尾空白字符
# 否则,函数第二个参数指定的字符将从该字符中去除 # 定义函数,传递2个参数:str1将被去除的字符串,str2接受用户给定的原始字串
# 这里要注意:str1有默认值,要注意它的位置。 string = input("请给定一个待处理的原始字串:")
repstr = input("请输入一个将被删除的字串:")
def newstrip(str2,str1=''):
# 定义x,y变量用于向正则中传递,x用于匹配原始字串开头的空白字符,y用于匹配原始字串结尾的空白字符
x = '^\s*'
y = '\s*$'
# 如果用户没有输入将被删除的字串,那么就返回去除头尾空白字符的原始字串,否则返回被去除指定字串的新字串
if str1 == '':
newstr = re.sub(r'%s|%s'%(x,y),'',str2)
print("你没有输入将被去除的字符,默认将去除首尾空白字符如果有的话")
else:
newstr = re.sub(str1,'',str2)
print("字符" + str1 + "将从原始字串中被去除")
return newstr
print("处理后的字串为:")
if repstr in string:
print(newstrip(string,repstr))
else:
print("你输入的字串不在原始字串中,或者不连续")

最新文章

  1. 百度富文本编辑器UEDITOR
  2. [转]在Ubuntu 下安装Redis 并使用init 脚本启动
  3. 一套简单可依赖的Javascript库
  4. eclipse下部署web工程的两种方式
  5. 客户端TortoiseSVN的安装及使用方法
  6. web.xml文件的作用
  7. LintCode-Word Search II
  8. 使用struts的模型驱动注意的问题
  9. iOS开发中常见的语句@synthesize obj = _obj 的意义详解
  10. openMP编程(上篇)之指令和锁
  11. Java安全套接字扩展——JSSE
  12. Ubuntu18.04关机卡死问题
  13. Android Studio 错误: 非法字符: '\ufeff'
  14. 撩课-Web大前端每天5道面试题-Day28
  15. C++ 获取类成员函数地址方法 浅析
  16. 2款适合HTML做音频和视频的插件
  17. MySQL 官方文档
  18. 1095 Cars on Campus
  19. leetCode(45):Min Stack
  20. unity文件写入与读取

热门文章

  1. .net操作InI文件
  2. spring 事务无效解决方法
  3. 使用Criteria 实现两表的左外连接,返回根对象
  4. 翻译Algorithms Unlocked
  5. IBM WebSphere ESB入门指南
  6. 你真的知道组件中的v-model吗?
  7. 给Linux系统/网络管理员准备的Nmap命令的29个实用范例
  8. js获取页面宽高
  9. angularjs下拉框空白
  10. 连接SQL SERVER数据库实例出错