[checkio] House password
((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})
위의 코드를 참고하여 작성합니다.
import re
def checkio(data):
rst = re.match('((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{10,})', data)
return bool(rst)
re.match(…) 코드에서 매치가 되지 않으면 none
이 반환되므로 bool()
함수를 사용하여 반환합니다.
Regular Expression
?=
positive lookahead 를 사용하여 찾습니다.
(?=.*\d)
: 숫자가 포함된 것을 확인한다.
(?=.*[a-z])
: 소문자가 포함된 것을 확인한다.
(?=.*[A-Z])
: 대문자가 포함된 것을 확인한다.
.{10,}
: 길이가 10이상인 것을 확인한다.
(?!) - negative lookahead
(?=) - positive lookahead
(?<=) - positive lookbehind
(?<!) - negative lookbehind
(?>) - atomic group
positive lookahead (?=ABC)
Matches a group after the main expression without including it in the result.
example
\d(?=px)
1pt 2
px 3em 4
px
negative lookahead (?!ABC)
Specifies a group that can not match after the main expression (if it matches, the result is discarded).
example
\d(?!px)
1
pt 2px 3
em 4px
positive lookbehind (?<=ABC)
Matches a group before the main expression without including it in the result
negative lookbehind (?<!ABC)
Specifies a group that can not match before the main expression (if it matches, the result is discarded)
ref
- http://www.mkyong.com/regular-expressions/how-to-validate-password-with-regular-expression/
- https://docs.python.org/2/library/re.html
- https://wikidocs.net/1642
- https://checkio.org/mission/house-password
- http://stackoverflow.com/questions/2973436/regex-lookahead-lookbehind-and-atomic-groups
- http://www.regular-expressions.info/lookaround.html
- http://regexr.com/
'Programming > Contest' 카테고리의 다른 글
[Code Jam to I/O 2016 for Women] Problem B. Dance Around The Clock (0) | 2016.04.09 |
---|---|
[coderbyte] First Reverse (0) | 2016.04.08 |
[checkio] Median (0) | 2016.04.06 |
[checkio] Non-unique Elements (0) | 2016.04.05 |
[codingame] The Descent (0) | 2014.12.13 |
댓글