The Find Users With Valid E-Mails interview question is a data validation task in SQL. You are given a Users table and need to find users whose email addresses follow a specific, strict format:
_, periods ., and dashes -.@leetcode.com.Companies like Meta and Google ask the Find Users With Valid E-Mails coding problem to test a candidate's proficiency with Regular Expressions (Regex) in SQL. Data cleaning and validation are major parts of data engineering, and the ability to write robust regex patterns is essential for ensuring data quality. It evaluations your attention to detail regarding character classes and boundaries.
This problem follows the SQL Regex Matching pattern.
^[A-Za-z][A-Za-z0-9_.-]*@leetcode[.]com$^: Start of string.[A-Za-z]: First character must be a letter.[A-Za-z0-9_.-]*: Subsequent characters can be letters, digits, underscores, dots, or dashes.@leetcode[.]com$: Must end exactly with the specified domain. (Note the [.] to treat the period literally).julia@leetcode.com: Valid.123_abc@leetcode.com: Invalid (starts with digit).abc-def.ghi_123@leetcode.com: Valid.abc@gmail.com: Invalid (wrong domain).abc@leetcode?com: Invalid (contains ?).. is a wildcard in regex and needs to be escaped or put in a character class [.] to match a literal period.- or _).Practice SQL regex syntax for different dialects (MySQL REGEXP, PostgreSQL ~, etc.). Although the logic is similar, the exact symbols for word boundaries or character classes can vary slightly. This is a common Database interview pattern requirement.