SQL regexp在搜索模式中包含NOT

时间:2014-05-04 12:33:59

标签: sql regex

我想运行以下查询来搜索电子邮件模式:

select * from users
where email regexp  Binary '[a-z]*[0-9][0-9][0-9]@yahoo.com';

我想找到所有电子邮件字符串,其中包含x字母,3位数字,以@ yahoo.com结尾:

example123@yahoo.com
admin754@yahoo.com

但是当前查询还会返回包含3位数字的字符串,例如example45653@yahoo.com 怎么办呢?

4 个答案:

答案 0 :(得分:1)

最简单的方法是使用not

where not (email regexp Binary '[a-z]*[0-9][0-9][0-9]@yahoo.com')

where (email not regexp Binary '[a-z]*[0-9][0-9][0-9]@yahoo.com')

一个警告:NULL的{​​{1}}值将使两个测试以及原始测试失败。

答案 1 :(得分:0)

你应该在正则表达式上放置锚点并按如下方式执行:

^[a-zA-Z]+\d{3}@yahoo\.com$

DEMO

答案 2 :(得分:0)

试试这个:

SELECT * FROM mytable WHERE mycolumn REGEXP "[a-zA-Z]+[[:digit:]]{3}@yahoo\\.com";

现场演示

http://regex101.com/r/tK1sS7

答案 3 :(得分:0)

尝试

\b[a-z]+[0-9]{3}@yahoo\.com\b

有关更多样本,请查看以下链接: