[REGEXP] Find Users With Valid E-Mails
링크
https://leetcode.com/problems/find-users-with-valid-e-mails/description/
문제
Write a solution to find the users who have valid emails.
A valid e-mail has a prefix name and a domain where:
The prefix name is a string that may contain letters (upper or lower case), digits, underscore '_', period '.', and/or dash '-'. The prefix name must start with a letter.
The domain is '@leetcode.com'.
Return the result table in any order.
The result format is in the following example.
정답
select *
from Users
where mail regexp '^[a-zA-Z][a-zA-Z0-9_.-]*@leetcode[.]com$'
# 해설
[a-zA-Z] = means mail should start from small or capital letter.
[a-zA-Z0-9_.-] = after that any letter or number or _ or . or -
@leetcode = after that combine with @leetcode
[.] = must come . after @leetcode
com = then com.
새롭게 이해한 내용
- 정규식 기호
. : 문자 하나를 나타낸다.
* : 앞에 나온 문자의 0개 이상 반복을 나타낸다.
^ : 문자열의 처음을 나타낸다.
$ : 문자열의 끝을 나타낸다.
[.] : 괄호 안의 문자열 일치를 확인한다.
{.} : 반복을 나타낸다.
| : or 를 나타낸다.
(관련 URL)https://dev.mysql.com/doc/refman/8.4/en/regexp.html
MySQL :: MySQL 8.4 Reference Manual :: 14.8.2 Regular Expressions
14.8.2 Regular Expressions Table 14.14 Regular Expression Functions and Operators Name Description NOT REGEXP Negation of REGEXP REGEXP Whether string matches regular expression REGEXP_INSTR() Starting index of substring matching regular expression REGE
dev.mysql.com