第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在多行中搜索特定行并將值存儲在變量中

如何在多行中搜索特定行并將值存儲在變量中

冉冉說 2022-01-18 21:20:26
我已將命令的輸出存儲chage -l user在變量中output,需要檢查用戶帳戶密碼是否未過期或將在 90 天內過期。import reoutput = '''Last password change                                    : Aug 26, 2017Password expires                                        : neverPassword inactive                                       : neverAccount expires                                         : neverMinimum number of days between password change          : 0Maximum number of days between password change          : 99999Number of days of warning before password expires       : 7'''regexp = re.compile(r'Password expires [ ]*(:*?)')match = regexp.match(output)if match:    VALUE = match.group(2)現在,我需要將值存儲在一個變量中以繼續(xù)前進但無法做到這一點。以上是我的代碼。理想情況下,VALUE 應該有“從不”。
查看完整描述

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)


查看完整回答
反對 回復 2022-01-18
  • 1 回答
  • 0 關注
  • 185 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號