前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >LeetCode MySQL 1517. Find Users With Valid E-Mails(正则表达式)

LeetCode MySQL 1517. Find Users With Valid E-Mails(正则表达式)

作者头像
Michael阿明
发布2021-02-19 09:57:30
8250
发布2021-02-19 09:57:30
举报
文章被收录于专栏:Michael阿明学习之路

文章目录

1. 题目

Table: Users

代码语言:javascript
复制
+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| user_id       | int     |
| name          | varchar |
| mail          | varchar |
+---------------+---------+

user_id is the primary key for this table. This table contains information of the users signed up in a website. Some e-mails are invalid.

Write an SQL query 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 query result format is in the following example.

代码语言:javascript
复制
Users
+---------+-----------+-------------------------+
| user_id | name      | mail                    |
+---------+-----------+-------------------------+
| 1       | Winston   | winston@leetcode.com    |
| 2       | Jonathan  | jonathanisgreat         |
| 3       | Annabelle | bella-@leetcode.com     |
| 4       | Sally     | sally.come@leetcode.com |
| 5       | Marwan    | quarz#2020@leetcode.com |
| 6       | David     | david69@gmail.com       |
| 7       | Shapiro   | .shapo@leetcode.com     |
+---------+-----------+-------------------------+

Result table:
+---------+-----------+-------------------------+
| user_id | name      | mail                    |
+---------+-----------+-------------------------+
| 1       | Winston   | winston@leetcode.com    |
| 3       | Annabelle | bella-@leetcode.com     |
| 4       | Sally     | sally.come@leetcode.com |
+---------+-----------+-------------------------+
The mail of user 2 doesn't have a domain.
The mail of user 5 has # sign which is not allowed.
The mail of user 6 doesn't have leetcode domain.
The mail of user 7 starts with a period.

来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/find-users-with-valid-e-mails 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

2. 解题

语法规则: https://www.runoob.com/mysql/mysql-regexp.html https://www.cnblogs.com/zhaopanpan/p/10133224.html

代码语言:javascript
复制
^ 表示开头
+ 匹配一个或多个,不包括空
[] 表示集合里的任意一个
\\ 用于转义特殊字符
a{m,n} 匹配m到n个a,左侧不写为0,右侧不写为任意
$ 表示以什么为结尾
代码语言:javascript
复制
# Write your MySQL query statement below
select * from Users
where mail regexp '^[a-zA-Z]+[a-zA-Z0-9_\\./\\-]{0,}@leetcode\\.com$'
order by user_id
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/07/19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • 1. 题目
  • 2. 解题
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档