HackerRank-Python/Regex
Prepare > Regex > Introduction > Matching Start & End
stem_sw
2023. 10. 10. 22:31
Matching Start & End | HackerRank
Use the ^ symbol to match the start of a string, and the $ symbol to match the end characters.
www.hackerrank.com
문제
Task
You have a test string S. Your task is to match the pattern Xxxxx.
Here, x denotes a word character, and X denotes a digit.
S must start with a digit X and end with . symbol.
S should be 6 characters long only.
코드
Regex_Pattern = r"^\d\w{4}\.$" # Do not delete 'r'.
import re
print(str(bool(re.search(Regex_Pattern, input()))).lower())
노트
^
The ^ symbol matches the position at the start of a string.
$
The $ symbol matches the position at the end of a string.
\d
- 숫자를 의미하는 정규표현식
- [0-9]
\w
- 알파벳, 숫자, 언더바 를 의미하는 정규표현식
- [a-zA-Z0-9_]