📜  python 从字符串中提取邮件 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:05.602000             🧑  作者: Mango

代码示例1
import re
line = "should we use regex more often? let me know at  321dsasdsa@dasdsa.com.lol"
match = re.search(r'[\w.+-]+@[\w-]+\.[\w.-]+', line)
print(match.group(0))
# '321dsasdsa@dasdsa.com.lol'

# or for multiple adresses
line = "should we use regex more often? let me know at  321dsasdsa@dasdsa.com.lol or dadaads@dsdds.com"
match = re.findall(r'[\w.+-]+@[\w-]+\.[\w.-]+', line)
print(match)
# ['321dsasdsa@dasdsa.com.lol', 'dadaads@dsdds.com']