|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
为什么这个程序没有屏蔽掉没有¥#@的2W开头的字符串呢
程序为:
import re
a=input("input")
strlist=a.split(",")
for word in strlist:
if len(word)>=6 and len(word)<=12:
if re.search("[a-z]",word) != "":
if re.search("[A-Z]",word) != "":
if re.search("[0-9]",word) != "":
if re.search("[$#@]",word) != "":
print(word)
本帖最后由 lxping 于 2022-12-15 20:37 编辑
正则表达式 re.search() 匹配不成功的时候返回 NoneType
- word = "2We3345"
- a = re.search("[$#@]",word)
- a
- a != ""
- True
- type(a)
- <class 'NoneType'>
- type("")
- <class 'str'>
复制代码
改一下
- import re
- a=input("input")
- strlist=a.split(",")
- for word in strlist:
- if len(word)>=6 and len(word)<=12:
- if re.search("[a-z]",word):
- if re.search("[A-Z]",word):
- if re.search("[0-9]",word):
- if re.search("[$#@]",word):
- print(word)
复制代码
运行结果
- inputABd1234@1,a F#,2w3E*,We3345
- ABd1234@1
复制代码
|
|