繁体   English   中英

Python / Jython解析电子邮件

[英]Python/Jython parse e-mail

我已经使用Jython解析了电子邮件,以获取电子邮件消息正文值。 现在,我具有主体价值,我想从中提取以下文本。

该正文包含文本,我想提取以下文本:

正文中发现以下行:

 [type]: mail
 [category]: Values
 [service]: testing
 [description]: Testing out automapping of email
 Line break Testing out automapping of email
 Line break Testing out automapping of email

现在,我想提取[说明]之后的所有值:这可能吗? 我尝试了这个:

desc = '[description]:'
res = findall("{}.*".format(desc), body)[0]

正则表达式可能的解决方案,但请考虑@StefanNch建议:

\\[description\\]:((?:.+\\n?)*)

import re
p = re.compile(ur'\[description\]:((?:.+\n?)*)')
test_str = u" [type]: mail\n [category]: Values\n [service]: testing\n [description]: Testing out automapping of email\n Line break Testing out automapping of email\n Line break Testing out automapping of email"
subst = u""

result = re.sub(p, subst, test_str)

re.search(p, test_str)

演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM