我需要一個正則運算式來驗證密碼,密碼必須是:長度為 8 個字符,2 個大寫字母,3 個小寫字母,1 個特殊字符和 2 個數字
([AZ]{2})([?!@#*%^&- ]{1})([0-9]{2})([az]{3})$ 這就是我想出來的with 但問題是它不匹配任何順序。
uj5u.com熱心網友回復:
使用前瞻:
^(?=(?:.*[a-z]){3})(?=(?:.*[A-Z]){2})(?=.*[?!@#*%^&- ])(?=(?:.*\d){2})[a-zA-Z?!@#*%^&- \d]{8}$
解釋:
^ // Assert is the beginning of the string
(?=(?:.*[a-z]){3}) // Positive lookahead to match exactly 3 lowercase letters
(?=(?:.*[A-Z]){2}) // Positive lookahead to match exactly 2 uppercase letters
(?=.*[?!@#*%^&- ]) // Positive lookahead to match exactly 1 special character
(?=(?:.*\d){2}) // Positive lookahead to match exactly 2 numbers
[a-zA-Z?!@#*%^&- \d]{8} // Assert that has exactly 8 of the defined characters
$ // Assert is the end of the string
測驗:RegExr
關于正則運算式知識的其他回復:
https://stackoverflow.com/a/22944075/11407290
https://stackoverflow.com/a/372??37468/11407290
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/447300.html
