HackerRank-Python/Regex

Prepare > Regex > Introduction > Matching Word & Non-Word Character

stem_sw 2023. 10. 10. 07:45
 

Matching Word & Non-Word Character | HackerRank

Use \w to match any word and \W to match any non-word character.

www.hackerrank.com

 

문제


Task

You have a test string S. Your task is to match the pattern xxxXxxxxxxxxxxXxxx
Here x denotes any word character and X denotes any non-word character.

 

 

=> xxxXxxxxxxxxxxXxxx구조를 S에서 찾아라. x는 알파벳과숫자, 언더바(_)이고 X는 그 외 모든 문자.

 

 

 

 

코드


Regex_Pattern = r"\w{3}\W\w{10}\W\w{3}"	# Do not delete 'r'.

import re

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

 

 

 

 

노트


\w

The expression \w will match any word character.
Word characters include alphanumeric characters (a-z, A-Z and 0-9) and underscores (_).

 

 

\W

\W matches any non-word character.
Non-word characters include characters other than alphanumeric characters ( a-z, A-Z and 0-9 ) and underscore (_).