Prepare > Regex > Character Class > Excluding Specific Characters
2023. 10. 26. 20:10ㆍHackerRank-Python/Regex
Excluding Specific Characters | HackerRank
Use the [^] character class to exclude specific characters.
www.hackerrank.com
문제
Task
You have a test string S.
Your task is to write a regex that will match with the following conditions:
- S must be of length 6.
- First character should not be a digit (1,2,3,4,5,6,7,8,9 or 0).
- Second character should not be a lowercase vowel (a,i,e,u or o).
- Third character should not be b, c, D or F.
- Fourth character should not be a whitespace character ( \r, \n, \t, \f or <space> ).
- Fifth character should not be a uppercase vowel (A,E,U,I or U).
- Sixth character should not be a . or , symbol.
코드
Regex_Pattern = r'^[^0-9][^auioe][^bcDF][^\s][^AEIOU][^\.,]$' # Do not delete 'r'.
import re
print(str(bool(re.search(Regex_Pattern, input()))).lower())
노트
^ 부정 문자 클래스
The negated character class [^] matches any character that is not in the square brackets.
Regex_Pattern = r'^\D[^auioe][^bcDF]\S[^AEIOU][^\.,]$' # Do not delete 'r'.
import re
print(str(bool(re.search(Regex_Pattern, input()))).lower())
- [^0-9] 를 \D로
- [^\s]를 \S로
- S는 무조건 6글자 이므로 ^와 $로 길이까지 지정
'HackerRank-Python > Regex' 카테고리의 다른 글
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 > Matching Specific Characters (0) | 2023.10.25 |
Prepare > Regex > Introduction > Matching Start & End (0) | 2023.10.10 |
Prepare > Regex > Introduction > Matching Word & Non-Word Character (0) | 2023.10.10 |