Prepare > Regex > Repetitions > Matching Zero Or More Repetitions
2023. 10. 30. 19:49ㆍHackerRank-Python/Regex
Matching Zero Or More Repetitions | HackerRank
Match zero or more repetitions of character/character class/group using the * symbol in regex.
www.hackerrank.com
문제
Task
You have a test string S.
Your task is to write a regex that will match S using the following conditions:
- S should begin with 1 or 2 digits.
- After that, S should have 3 or more letters (both lowercase and uppercase).
- Then S should end with up to 3 . symbol(s). You can end with 0 to 3. symbol(s), inclusively.
코드
Regex_Pattern = r'^\d{1,2}[a-zA-Z]{3,}\.{0,3}$' # Do not delete 'r'.
import re
print(str(bool(re.search(Regex_Pattern, input()))).lower())
노트
{x,y}
The {x,y} tool will match between x and y (both inclusive) repetitions of character/character class/group.
문자, 문자클래스, 그룹에 대해 최소 x에서 최대 y번 반복을 지정
- w{3,5} : It will match the character w 3, 4 or 5 times.
- [xyz]{5,} : It will match the character x, y or z 5 or more times.
- \d{1, 4} : It will match any digits 1, 2, 3, or 4 times.
- [123]{,3} : 1|2|3 을 0번에서 3번까지 반복
'HackerRank-Python > Regex' 카테고리의 다른 글
Prepare > Regex > Repetitions > Matching One Or More Repetitions (0) | 2023.11.07 |
---|---|
Prepare > Regex > Repetitions > Matching Zero Or More Repetitions (1) | 2023.11.06 |
Prepare > Regex > Repetitions > Matching {x} Repetitions (0) | 2023.10.28 |
Prepare > Regex > Character Class > Matching Character Ranges (0) | 2023.10.27 |
Prepare > Regex > Character Class > Excluding Specific Characters (0) | 2023.10.26 |