본문 바로가기

데이터 - 기본 코드 및 알고리즘 연습/Codewar

[Codewars] Regex Password Validation

▶  문제 : 

▶  내 답안 :  특수문자제거&대문자&소문자&숫자

regex = "^(?!(?=.*[!@#$^&%*()+=\_\-\[\]\\\/{}|:<>?,. ]).)(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{6,}"

▶  모범답안1 : 

regex = "^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])[^\W_]{6,}$"

▶  모범답안2 : 

from re import compile, VERBOSE

regex = compile("""
^              # begin word
(?=.*?[a-z])   # at least one lowercase letter
(?=.*?[A-Z])   # at least one uppercase letter
(?=.*?[0-9])   # at least one number
[A-Za-z\d]     # only alphanumeric
{6,}           # at least 6 characters long
$              # end word
""", VERBOSE)

 

▶  배워야할 부분 ( regex &(and) 조건문 )

그림 : https://regexper.com/

 

Regexper

 

regexper.com

 

 

실시간 확인 : https://regex101.com/

 

regex101: build, test, and debug regex

Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java. Features a regex quiz & library.

regex101.com