I have parsed en e-mail message using Jython to get the e-mail mesages body value. Now I have the body value and I'd like to extract the following text from it.
The body contains text and I would like to extract the following text:
There are rows found in the body:
[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
Now I would like to extract all the value after the [description]: Is this possible? I tried this:
desc = '[description]:'
res = findall("{}.*".format(desc), body)[0]
A regex possible solution, but consider @StefanNch suggestion:
\\[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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.