regex 正则表达式在Python中\n不匹配[重复]

hmtdttj4  于 2022-11-18  发布在  Python
关注(0)|答案(1)|浏览(164)

此问题在此处已有答案

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
我的代码:

  1. 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

x33g5p2x

x33g5p2x1#

您正在寻找DOTALL旗标。
https://docs.python.org/3/library/re.html#re.DOTALL
此外,有时MULTILINE标志与包含换行符的文本相关。

相关问题