开发者

Regexp to check e-mail address

开发者 https://www.devze.com 2023-02-24 07:02 出处:网络
I would like to know how to use MySQL\'s REGEXP or RLIKE feature for the two following tasks: Task #1 Select all e-mail addresses, but only return the component after the @ and before the first . in

I would like to know how to use MySQL's REGEXP or RLIKE feature for the two following tasks:

Task #1

Select all e-mail addresses, but only return the component after the @ and before the first . in the domain. So say I had 3 emails in a table... bob@123.com, bill@456.com, ben@789.com I would just want it to return 3 results of 123, 456, 789.


Task #2

When used in a WHERE clause, I would like to only match where the same part of the domain (after the @ and before the first .) meets a certain criteria.开发者_开发知识库 For arguments sake, lets say this is 123, 456 or 789.


Task #1 - there is no way to do this, MySQL can use REGEXPS only for comparision

Task #2 -

SELECT * FROM table WHERE field REGEXP '^[^@]+@(123|456|789)\\..*$'
0

精彩评论

暂无评论...
验证码 换一张
取 消