Python Regular Expression checks the validity of the password and the validity of the python password.
The customer's system upgrade requires that the user's password comply with certain rules, that is, including uppercase and lowercase letters, numbers, and symbols. The length is no less than 8. Therefore, a simple test program is written with python:
# Encoding = UTF-8 # coding # Name: Module 1 # Purpose: ## Author: Administrator ## Created: 10-06-2014 # Copyright: (c) Administrator 2014 # Licence: <your licence> # Export import redef checklen (pwd): return len (pwd)> = 8def checkContainUpper (pwd): pattern = re. compile ('[A-Z] +') match = pattern. findall (pwd) if match: return True else: return Falsedef checkContainNum (pwd): pattern = re. compile ('[0-9] +') match = pattern. findall (pwd) if match: return True else: return Falsedef checkContainLower (pwd): pattern = re. compile ('[a-z] +') match = pattern. findall (pwd) if match: return True else: return Falsedef checkSymbol (pwd): pattern = re. compile ('([a-z0-9A-Z]) +') match = pattern. findall (pwd) if match: return True else: return Falsedef checkPassword (pwd): # determine whether the password length is valid lenOK = checklen (pwd) # determine whether to include uppercase letters upperOK = checkContainUpper (pwd) # determine whether to include lowercase letters lowerOK = checkContainLower (pwd) # determine whether to include numbers numOK = checkContainNum (pwd) # determine whether the symbol symbolOK = checkSymbol (pwd) print (lenOK) print (upperOK) print (lowerOK) print (numOK) print (symbolOK) is included) return (lenOK and upperOK and lowerOK and numOK and symbolOK) def main (): if checkPassword ('helloworld # 000000'): print ('checked pass') else: print ('check failed ') if _ name _ =' _ main _ ': main ()
There are not many regular expressions at ordinary times. I don't know how to write a regular expression to meet the requirements. I am using a stupid method. Please kindly advise if I have a regular expression test!