2014-09-24 57 views
0

我想,根據圖案 xxx.xxx所有行頭(只) 其中x是從1到9或任何字母一批Mysql的正則表達式容易

我表達不工作REGEXP '[a-z]{1,3}\.[a-z]{1,3}'

Thx!

UPD:Thx所有,但不起作用! 我tryed這麼

SELECT email, registered, voted, ip, agent 
FROM `voters` 
WHERE member =199 
AND DATE_FORMAT(voted, '%Y-%m-%d') < '2014-09-23' 
AND SUBSTRING_INDEX(email, '@', 1) 
REGEXP '[a-zA-Z1-9]{3}\.[a-zA-Z1-9]{3}' 

結果:

[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 

UPD 2:Itryed變化圖案,從而'[a-zA-Z1-9]{3}[\.]{1}[a-zA-Z1-9]{3}' 結果:

[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 

沒有好,becouse前後超過3個符號「 「。

+0

試試'[A-ZA-Z1-9] {3} \ [A-ZA-Z1-9] {3}' – 2014-09-24 13:08:14

+0

不起作用,經過3個符號和幾個「。」 – 2014-09-24 13:23:04

回答

0

[a-z]僅匹配小寫字母。您還需要指定大寫,數字1-9。

而量詞應該修改。 {1-3}相當於前一模式的1至3倍。使用{3}匹配3次。

REGEXP '[a-zA-Z1-9]{3}\.[a-zA-Z1-9]{3}' 
0

應該

[a-zA-Z1-9]{3}\.[a-zA-Z1-9]{3} 

允許3 上期的兩側。

和你說的任何字母。

1

如果你想要的是三個字母或數字後面加一個點,後緊跟三個字符以相同的條件,而不是更多的之前和之後,然後你必須使用

REGEXP '^[a-zA-Z1-9]{3}\.[a-zA-Z1-9]{3}$' 

特殊字符^$有這個意思:

character  meaning 
---------------------------------------------- 
    ^  Match the beginning of a string. 
    $   Match the end of a string.