请问,如何用正则表达式将列表中的邮箱信息提取出?如下:
l1=['a', 'b', 'c', 'd', 'E-Mail:abcdefg@qq.com', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
如何将abcdefg@qq.com提出?
请问,如何用正则表达式将列表中的邮箱信息提取出?如下:
l1=['a', 'b', 'c', 'd', 'E-Mail:abcdefg@qq.com', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
如何将abcdefg@qq.com提出?
额外加了一个邮箱,都能提取:
l1=['@', 'b', 'c', 'd', 'E-Mail:abcde123@qq.com', 'qr15@163.com', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
str_mail = []
for i in l1:
# print i
# 邮箱中含有'@',且不会出现在第一位,所以nPos > 0的满足条件
nPos = i.find('@')
if nPos > 0:
# 邮箱有前缀和后缀
# 后缀直接提取即可
# 前缀中不得有特殊字符和空格
# 也就是前缀中只能包含字母和数字
fon = ""
pos = i[nPos : len(i)] # 含有@
for j in range(nPos - 1, 0, -1):
if i[j].isdigit() or i[j].isalpha():
fon = i[j] + fon
else:
break
cur_email = fon + pos
str_mail.append(cur_email)
print str_mail