7.18.1
import re
def testPassword(password):
password = str(password)
upperRegex = re.compile(r'[A-Z]')
lowerRegex = re.compile(r'[a-z]')
numRegex = re.compile(r'[0-9]')
if len(password) < 8:
print('The password must be more than 8 digits.')
return
elif not upperRegex.search(password):
print('The password must contain uppercase characters.')
return
elif not lowerRegex.search(password):
print('The password must contain lowercase characters.')
return
elif not numRegex.search(password):
print('The password must contain digits characters.')
return
print('The password is strong enough!')
return
while True:
password = input('Please input your password:\n')
testPassword(password)
7.18.2
import re
def reStrip(string, words):
spaceRegex = re.compile(r'^(\s*)(.*[^\s])(\s*)$')
wordRegex = re.compile(r'^([%s]*)(.*[^%s])([%s]*)$'
%(words, words, words))
mo = spaceRegex.search(string)
if (mo.group(1) or mo.group(3)):
print('''The string has white space, so the result is: \n'''
+ mo.group(2))
return
else:
mo = wordRegex.search(string)
print('''The string has no white space, so the result is: \n'''
+ mo.group(2))
return
while True:
string = input('Please input the string:\n')
words = input('Please input the unwanted words:\n')
reStrip(string, words)