使用正則表達式re

郵箱可以以數字和字母開頭,但是不能以下劃線開頭,以.com結尾,返回郵箱的個數

import re

str1 = '[email protected]@[email protected]'
reg_str1 = r'([a-zA-Z0-9]+[\.\w]*@[\w]+\.com)'
mod = re.compile(reg_str1)
items = re.findall(reg_str1,str1)
for item in items:
    print item
print len(items)

output:

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章