簡體   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