python 學習 正規表示式 強口令檢測

2021-10-04 01:31:46 字數 1422 閱讀 2583

寫乙個函式,它使用正規表示式,確保傳入的口令字串是強口令。強口令的定義是:長度不少於 8 個字元,同時包含大寫和小寫字元,至少有一位數字。你可能需要用多個正規表示式來測試該字串,以保證它的強度。

下面展示**

#! python3

# strongpassworddetection.py # 強口令檢測 輸入一段口令

# 強口令:長度不少於8個字元 同時包含大寫和小寫 至少有一位數字

import re

def strongpassworddetection

(password):if

len(password)

>=8:

passregex_1 = re.

compile

(r'[a-z]').

search

(password)

passregex_2 = re.

compile

(r'[a-z]').

search

(password)

passregex_3 = re.

compile

(r'\d').

search

(password)

if passregex_1 and passregex_2 and passregex_3:

print

('this password is strongpassword'

)else

:print

('this password is not strongpassword'

)else

:print

('this password is not strongpassword'

)password =

input()

strongpassworddetection

(password)

12344saffsg676

this password is strongpassword

122334456

this password is not strongpassword

1212233

this password is not strongpassword

123asd

this password is not strongpassword

aaaaaaaaffff

this password is not strongpassword

iiiiffg4565

this password is strongpassword

正規表示式 強口令檢測(Python)

強口令檢測 寫乙個函式,它使用正規表示式,確保傳入的口令字串是強口令。強口令的定義是 長度不少於8 個字元,同時包含大寫和小寫字元,至少有一位數字。你可能需要用多個正規表示式來測試該字串,以保證它的強度。因為字串需要同時滿足多個正規表示式,所以考慮將多個表示式放入列表中,使用正則匹配時對列表進行遍歷...

Python 正規表示式學習(二)正規表示式語法

一,單一字元匹配 1 匹配任意字元 import re res re.match r a.abcd print res.group 列印結果 abc一點.表示匹配任意的字元。上面的 表示匹配a後面的任意兩個字元。必須從a開始。若寫成 b.則會發生錯誤。2 匹配指定字元 如 0 9a za z 表示 ...

python正規表示式學習

今天學習了python中有關正規表示式的知識。關於正規表示式的語法,不作過多解釋,網上有許多學習的資料。這裡主要介紹python中常用的正 則表示式處理函式。re.match 嘗試從字串的開始匹配乙個模式,如 下面的例子匹配第乙個單詞。import re text jgood is a handso...