Python 从文本中提取电子邮件

Python 从文本中提取电子邮件

要从文本中提取电子邮件,我们可以使用正则表达式。在下面的示例中,我们使用正则表达式包来定义电子邮件ID的模式,然后使用 findall() 函数来检索与此模式匹配的文本。

import re
text = "Please contact us at [email protected] for further information."+\
        " You can also give feedbacl at [email protected]"


emails = re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", text)
print emails

当我们运行上述程序时,我们会得到以下输出:

['[email protected]', '[email protected]']

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程