해커랭크에서는 프로그래머스에서 못봤던 regex를 이용하는 문제도 있었다
Pattern | Description |
---|---|
* | Matches zero or more instances of the preceding String |
+ | Matches one or more instances of the preceding String |
. | Matches any single character |
? | Matches zero or one instance of the preceding Strings |
^ | ^ matches the beginning of a String |
$ | $ matches the ending of a String |
[abc] | Matches any character listed in between the square brackets |
[^abc] | Matches any character not listed in between the square brackets |
[A-Z] | Matches any letter in uppercase |
[a-z] | Matches any letter in lowercase |
[0-9] | Matches any digit between 0-9 |
[[:<:]] | Matches the beginning of words |
[[:>:]] | Matches the end of words |
[:class:] | Matches any character class |
p1|p2|p3 | Mathes any of the specified pattern |
{n} | Matches n instances of the preceding element |
{m,n} | Matches m through n instances of the preceding element |
모음[AEIOU]으로 시작(^)하는 도시이름 출력하기
SELECT DISTINCT CITY
FROM STATION
WHERE CITY REGEXP '^[AEIOU]'
모음[AEIOU]으로 끝($)나는 도시이름 출력하기
SELECT DISTINCT CITY
FROM STATION
WHERE CITY REGEXP '[AEIOU]$'
모음[AEIOU]으로 시작(^)하지도 끝($)나지도 않는 도시이름 출력하기
SELECT DISTINCT CITY
FROM STATION
WHERE CITY NOT REGEXP '^[AEIOU]'
AND CITY NOT REGEXP '[AEIOU]$'
문자열의 총 길이가 n 작을 때는 총 문자열이 출력된다.
아스키값 숫자를 문자로 바꿔준다. 65 -> A
문자를 아스키값으로 바꿔준다. A -> 65
SELECT CHARINDEX('a','apple') # 1
SELECT CHARINDEX('p','apple') # 2
두개 이상의 문자열을 합쳐준다
맨 처음의 separator로 문자열들을 분리하면서 합쳐준다
SELECT CONCAT('PANDA','FAMILY','LOVE');
# PANDAFAMILYLOVE
SELECT 'AI'+'LE'+'FU';
# AILEFU
SELECT CONCAT_WS(' : ','PANDA','FAMILY','CUTE');
# PANDA : FAMILY : CUTE