[英]REGEX - (using Python 3.5) - finding strings in file
我正在打開一個.msg前景文件,需要從中提取一些特定數據。 我對regex還是有點陌生,找不到我需要的東西。
以下是文件中的數據,其中包含一些選項卡,看起來像是fyi:
NEWS ID: 918273/1
TITLE: News Platform Solution Overview (CNN) (US English Session)
ACCOUNT: supernewsplatformacct (55712)
Your request has been completed.
Output Format MP4
Please click on the "Download File" link below to access the download page.
Download File <http://news.downloadwebsitefake.com/newsid/file1294757493292848575.mp4>
我需要:
918273
-from- NEWS ID: 918273/1
News Platform Solution Overview (CNN) (US English Session)
-from- TITLE: News Platform Solution Overview (CNN) (US English Session)
supernewsplatformacct
-from- ACCOUNT: supernewsplatformacct (55712)
http://news.downloadwebsitefake.com/newsid/file1294757493292848575.mp4
-from- Download File <http://news.downloadwebsitefake.com/newsid/file1294757493292848575.mp4>
我正在努力
[\\n\\r][ \\t]*NEWS ID:[ \\t]*([^\\n\\r]*)
但是沒有運氣。 任何幫助將不勝感激!
msg = """NEWS ID: 918273/1
TITLE: News Platform Solution Overview (CNN) (US English Session)
ACCOUNT: supernewsplatformacct (55712)
Your request has been completed.
Output Format MP4
Please click on the "Download File" link below to access the download page.
Download File <http://news.downloadwebsitefake.com/newsid/file1294757493292848575.mp4>"""
import re
regex = r'[^:]+:\s+(.*)$|[^<]+<([^>]+)>'
matches = [re.match(regex, i).group(1) or re.match(regex, i).group(2) for i in msg.split('\n') if i and re.match(regex, i)]
print(matches)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.