SQL 50, decoded
0 of 50 solved/50

1517. Find Users With Valid E-Mails

SQL 50 · Advanced String Functions, Regex, Clause (day 7). Decode it with the hints, solve it on LeetCode, then compare with the reference solution in MySQLPostgreSQL.

EasySolve it on LeetCode ↗

Your work

Hints

Open one at a time. Try to finish with as few as you can.

1. What does one output row represent?
One user.
2. Approach
REGEXP_LIKE(mail, '^[a-zA-Z][a-zA-Z0-9_.-]*@leetcode[.]com$', 'c').mail ~ '^[a-zA-Z][a-zA-Z0-9_.-]*@leetcode[.]com$'.
3. The trap
Escape the dot and anchor with ^ and $. MySQL regex is case-insensitive by default, so @LEETCODE.COM slips through without the 'c' flag.Escape the dot and anchor with ^ and $. ~ is case-sensitive (~* is not), which is what you want here.

Reference solution

Tested on MySQL 8.0 and PostgreSQL 16. Switch dialect at the top of the page.

Show the MySQLPostgreSQL solution
SELECT *
FROM Users
WHERE REGEXP_LIKE(mail, '^[a-zA-Z][a-zA-Z0-9_.-]*@leetcode[.]com$', 'c');SELECT *
FROM Users
WHERE mail ~ '^[a-zA-Z][a-zA-Z0-9_.-]*@leetcode[.]com$';

Patterns used

Phrase finder · MySQL vs PostgreSQL