此问题在此处已有答案:
matching any character including newlines in a Python regex subexpression, not globally(2个答案)
11天前关闭。
我使用下面的正则表达式从邮件中提取电子邮件。Hi Helpdesk, I'm reaching out to you to ask for help about an accident I had. Is this the correct contact for accidental damages?\nTommaso Massari\nData Scientist\ntommaso_massari@gmail.com
我的代码:
from_email = str(re.findall('\s*[a-zA-Z]*.*\s*[\\n]([a-zA-Z]*.*[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,})',firstrow['message']))
它不会返回Python中的任何内容。
预期输出:tommaso_massari@gmail.com
1条答案
按热度按时间x33g5p2x1#
您正在寻找
DOTALL
旗标。https://docs.python.org/3/library/re.html#re.DOTALL
此外,有时
MULTILINE
标志与包含换行符的文本相关。