HackerRank-Python/Regex

Prepare > Regex > Repetitions > Matching One Or More Repetitions

stem_sw 2023. 11. 7. 19:46
 

Matching One Or More Repetitions | HackerRank

Match zero or more repetitions of character/character class/group with the + symbol.

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 more digits.
  • After that, S should have 1 or more uppercase letters.
  • S should end with 1 or more lowercase letters.

=> S는 하나이상의 숫자, 하나이상의 대문자, 하나이상의 소문자로 구성

 

 

 

 

코드


Regex_Pattern = r'^\d+[A-Z]+[a-z]+$'	# Do not delete 'r'.

import re

print(str(bool(re.search(Regex_Pattern, input()))).lower())

 

 

 

 

노트


+ 1번 이상의 횟수

The + tool will match one or more repetitions of character/character class/group.

  • w+ : It will match the character w 1 or more times.
  • [xyz]+ : It will match the character xy or z 1 or more times.
  • \d+ : It will match any digit 1 or more times.
  • {1,} 와 같은 의미