我正在尝试让我的代码检查用户输入是否仅包含以下字符:"!$%^&*()_-+="
如果它包含任何其他字符,则应减去分数。我尝试了这个,但它不能正常工作:
if "a-z" not in password and "A-Z" not in password and "0-9" not in password:
points = points - 1
我该如何解决这个问题?
谢谢
最佳答案
您可以通过转义上面列出的字符来使用正则表达式:
import re
s = "_%&&^$"
if not re.findall("^[\!\$\%\^\&\*\(\)\_\-\+\=]+$", s):
points -= 1
关于Python如何检查输入是否只包含某些字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47164260/