SQL/MySQL 이론

정규표현식

관재탑 2022. 8. 12. 16:24

https://www.hackerrank.com/challenges/weather-observation-station-6/problem?isFullScreen=true 

 

Weather Observation Station 6 | HackerRank

Query a list of CITY names beginning with vowels (a, e, i, o, u).

www.hackerrank.com

SELECT DISTINCT city
FROM station
WHERE city REGEXP "^[aeiou].*"

RegExp : 모음으로 시작하면서 뭐로 끝나도 상관없다.

[] : 안에 하나라도 포함되고, or로 연결시켜준다고 생각하면 편하다.

^ : 바로 뒤에 오는 문자로 시작

. : 뭐가 와도 상관없음, 한 글자를 뜻함

* : 앞에 오는게 0개나 그 이상 몇개가 와도 상관없음

 

 

 

https://www.hackerrank.com/challenges/weather-observation-station-7/problem?isFullScreen=true 

 

Weather Observation Station 7 | HackerRank

Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION.

www.hackerrank.com

SELECT DISTINCT CITY
FROM STATION
WHERE CITY REGEXP ".*[aeiou]$"

RegExp : 모음으로 끝나면서 앞에는 뭐로 시작하든 상관없다.

 

 

 

https://www.hackerrank.com/challenges/weather-observation-station-8/problem?isFullScreen=true 

 

Weather Observation Station 8 | HackerRank

Query CITY names that start AND end with vowels.

www.hackerrank.com

SELECT DISTINCT CITY
FROM STATION
WHERE CITY REGEXP "^[aeiou].*[aeiou]$"

RegExp : 모음으로 시작하고 끝나며 가운데는 뭐가 와도 상관없다.

 

 

 

https://www.hackerrank.com/challenges/weather-observation-station-9/problem?isFullScreen=true 

 

Weather Observation Station 9 | HackerRank

Query an alphabetically ordered list of CITY names not starting with vowels.

www.hackerrank.com

SELECT DISTINCT CITY
FROM STATION
WHERE CITY NOT REGEXP "^[aeiou].*"

RegExp : 모음으로 시작하지 않은 것을 가져옴

 

 

정규표현식 연습 사이트

https://regexone.com/

 

RegexOne - Learn Regular Expressions - Lesson 1: An Introduction, and the ABCs

Regular expressions are extremely useful in extracting information from text such as code, log files, spreadsheets, or even documents. And while there is a lot of theory behind formal languages, the following lessons and examples will explore the more prac

regexone.com

 

 

https://regexr.com/

 

RegExr: Learn, Build, & Test RegEx

RegExr is an online tool to learn, build, & test Regular Expressions (RegEx / RegExp).

regexr.com