2016-05-07 146 views
0

我運行此查詢:正則表達式的SQL查詢

SELECT DISTINCT email FROM `users` WHERE `email` REGEXP '^[a-zA-Z0-9._-]+(@outlook.com)$' and email NOT LIKE '%sex%' and email NOT LIKE '.%' and email NOT LIKE '-%' or email LIKE '%@live.com' AND userid > 10000 AND email NOT LIKE '%sex%' AND email NOT LIKE '%+%' and email NOT LIKE '.%' and email NOT LIKE '-%' 

和我的問題是,在該行的結果我得到了域@ live.com 例如這個結果invaild電子郵件地址:「一個 [email protected]」。 vaild電子郵件沒有中文字符。 如何忽略/過濾郵件結果中的無效字符? 我改變了我的查詢到這一點:

REGEXP '^[a-zA-Z0-9._-]+(@outlook.com|@live.com) 

但問題是,我得到@ outlook.com的電子郵件,他們的用戶ID超過10000 ,所以我刪除了「用戶ID> 10000」 現在的問題我是否收到@ live.com的電子郵件,其用戶ID是10000 我想要做什麼? 謝謝

+0

如何正在註冊相關的電子郵件療法用戶ID上outlook.com VS live.com? – Mike

+0

在高級語言中執行正則表達式操作嗎? – hd1

+0

無論如何,這個查詢如何?WHERE(\\ email'' REGEXP'^ [a-zA-Z0-9 ._-] +(@ outlook.com)$'AND userid <10000)OR(\'email \ 'REGEXP'^ [a-zA-Z0-9 ._-] +(@ live.com)$'AND userid> = 10000)'?? – Mike

回答

0

您只在REGEX的末尾添加一個$。在樣品你可以看到什麼是你的正則表達式的結果

樣品

MariaDB []> SELECT *, b REGEXP '^[a-zA-Z0-9._-]+(@outlook.com|@live.com)$' as result FROM abc ; 
+----+--------------------+--------+ 
| id | b     | result | 
+----+--------------------+--------+ 
| 38 | [email protected] |  0 | 
| 47 | [email protected] |  1 | 
| 48 | [email protected] |  1 | 
| 49 | a執[email protected]  |  0 | 
| 50 | [email protected]  |  1 | 
+----+--------------------+--------+ 
5 rows in set (0.00 sec) 

MariaDB []>