使用Python为纯文本构造正则表达式

2024-06-07 15:39:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个如下所示的文本格式,我需要使用正则表达式提取文本,对于每个键,我都有一个3digit数字,这可能有助于提取文本。我也能够使用该逻辑提取文本。请帮助我从下面的其他行获取值,直到我得到下一个数字或:符号

示例文本文档

200 Testresults:
Negative - blood sample shows a negative result 



200 study: lung issues
Disease code: 1#0045252452



200 Comments: 
Results should be tezted for the confirmation of Covid-19 with the assigned physican 
samples have been attached in the report 


200 Date: 02/05/2020

RE:示例代码

newtext = re.compile(r'^\d{3} [a-z].*')

必需的Json

{"Testresults":"Negative - blood sample shows a negative result ","study":"lung issues","Comments":"Results should be tezted for the confirmation of Covid-19 with the assigned physican samples have been attached in the report","Date":"02/05/2020"}


Tags: thesample文本示例数字resultcommentsshows

热门问题