1 回答

TA貢獻1802條經驗 獲得超6個贊
re.match不會在整個字符串中查找模式,而是會在字符串的開頭匹配它(就像正則表達式以 開頭一樣^)。所以你需要re.search,它將檢查整個目標字符串的模式:
import re
output = '''Last password change : Aug 26, 2017
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
'''
regexp = re.compile(r'Password expires\s+: (.*)')
match = regexp.search(output)
if match:
VALUE = match.group(1)
print(VALUE)
添加回答
舉報