2015-06-20 76 views
0

正則表達式,如何過濾[email protected]:[email protected]沒有:正則表達式,如何過濾任何@任何:任何@任何沒有'':''?

我需要一個Python的正則表達式代碼,用來單詞列表更新2.7,我想過濾任何郵件即:

[email protected]: 

[email protected]: 

最終結果:

[email protected] 

[email protected] 

我有以下的正則表達式 -

(^[[email protected]#$%^&*.,?][email protected][a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$) 

哪個過濾器[email protected]

[email protected] 

[email protected] 

,而不是

[email protected]: 
+0

是':'總是結束? – itzMEonTV

+0

如果它始終位於結果字符串的末尾,爲什麼不移除它(或將其替換爲空字符串)? – Isxek

+0

您不需要正則表達式,只需使用rstrip作爲@Padraic坎寧安建議如下。 – suvayu

回答

0

伸出rstrip它,如果它的存在,它會被刪除,如果不是什麼都不會獲得剝奪:

"[email protected]:".rstrip(":") 
0

你的正則表達式似乎不必要的複雜性。電子郵件ID的用戶名部分必須僅包含字母,數字和句點。某些郵件服務允許使用連字符和下劃線。但是gmail嚴格要求只有前三個。

因此你的正則表達式將如下:

'[\w.][email protected][\w.]+' 

這也將消除你「:」問題,因爲冒號「:」不被視爲一個單詞字符(\ W)的正則表達式引擎。

您可以使用re模塊中的findall()方法查找您提供的字符串中的所有電子郵件ID。它會返回給你一個列表。

filtered_emails = re.findall(r'[\w.][email protected][\w.]+', string) 

for email in filtered_emails: 
    print email 

Google python class具有真正好的教程和正則表達式的例子。去參觀。

+0

工作的結果是這樣的:[email protected]:1234,[email protected]等...不工作 –

+0

哦....是啊.....你可以修改一些正則表達式。 r'[\ w。] + @ [a-z。] +'。這將工作正常。 –

+0

Downlaz plz Word List Updater 2.7很容易找到谷歌,你可以嘗試自己,不工作,等待我會給你我自己的工具:https://www.mediafire.com/?cs1ncicsw12p0zu,現在請嘗試 –

相關問題