2023. 10. 9. 19:17ㆍHackerRank-Python/Regex
Matching Whitespace & Non-Whitespace Character | HackerRank
Use \s to match whitespace and \S to match non whitespace characters in this challenge.
www.hackerrank.com
문제
Task
You have a test string S. Your task is to match the pattern XXxXXxXX
Here, x denotes whitespace characters, and X denotes non-white space characters.
Note
This is a regex only challenge. You are not required to write code.
You have to fill the regex pattern in the blank (_________).
=> x는 화이트스페이스, X는 화이트 스페이스를 제외한 문자. 문자열 S에서 XXxXXxXX 구조를 search하라.
코드
Regex_Pattern = r"\S{2}\s\S{2}\s\S{2}" # Do not delete 'r'.
import re
print(str(bool(re.search(Regex_Pattern, input()))).lower())
노트
\s
\s matches any whitespace character [ \r\n\t\f ].
- \r : 캐리지 리턴(커서를 해당 줄의 맨 앞으로)
- \n : 줄바꿈
- \t : 탭(tab)
- \f : 폼 피드(커서를 다음 줄로, 일종의 줄바꿈), 페이지 나누기 라고 설명하는 곳도 있음
\S
\S matches any non-white space character.
참조
[파이썬] 이스케이프 문자
문자열 이스케이프 문자열을 다룰 때 특수 문자를 처리하기 위해 이스케이프 문자라는 걸 사용합니다. 특수한 의미를 갖는 문자를 일반 문자처럼 쓰거나 줄바꿈을 하기 위해서 씁니다. 이스케
seong6496.tistory.com
파이썬 이스케이프 시퀀스
표기 명칭 동작 \a 벨 소리(alert) 청각적 혹은 시각적 경보를 생성 \b 백스페이스 커서를 한 칸 앞으로 이동 \f 폼 피드(form feed) 커서 위치를 페이지의 처음으로 이동 \n 줄 바꿈 문자열 안에서 행을
laoching.tistory.com
'HackerRank-Python > Regex' 카테고리의 다른 글
Prepare > Regex > Introduction > Matching Start & End (0) | 2023.10.10 |
---|---|
Prepare > Regex > Introduction > Matching Word & Non-Word Character (0) | 2023.10.10 |
Prepare > Regex > Introduction > Matching Digits & Non-Digit Characters (1) | 2023.10.07 |
Prepare > Regex > Introduction > Matching Anything But a Newline (1) | 2023.10.06 |
Prepare > Regex > Introduction > Matching Specific String (1) | 2023.10.05 |