Filter the user table to return only users whose email addresses match the required school-domain pattern.
Problem
You are given a table of users. Each row contains a user's information, including an email field.
Return the users whose email addresses are considered valid according to the required format:
- The email must start with a lowercase letter.
- The remaining characters before
@may contain lowercase letters, digits, underscores, periods, or hyphens. - The domain must be exactly
leetcode.com.
Only rows matching the rule should be included in the result.
Notes
- Matching is case-sensitive.
- The domain must end exactly with
leetcode.comand should not contain extra characters before or after it. - This is a filtering problem; no transformation of the email string is needed.
Input Format
A table Users with at least these columns:
user_idnamemail
You should filter rows based on the validity rule for mail.
Output Format
Return the rows of Users that satisfy the valid email rule, preserving the original columns.
Constraints
- Email addresses are case-sensitive.
- Valid emails follow the pattern:
^[a-z][a-z0-9._-]*@leetcode\.com$ - Return all matching rows.
Example 1
Input
Users table +---------+-------+--------------------------+ | user_id | name | mail | +---------+-------+--------------------------+ | 1 | Alice | alice@leetcode.com | | 2 | Bob | Bob@leetcode.com | | 3 | Carol | carol-123@leetcode.com | | 4 | Dave | dave@leet-code.com | +---------+-------+--------------------------+
Output
+---------+-------+--------------------------+ | user_id | name | mail | +---------+-------+--------------------------+ | 1 | Alice | alice@leetcode.com | | 3 | Carol | carol-123@leetcode.com | +---------+-------+--------------------------+
Explanation
alice@leetcode.com and carol-123@leetcode.com match the allowed format. Bob@leetcode.com starts with an uppercase letter, and dave@leet-code.com has the wrong domain.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.