Regex 从同一行和下一行获取值
我有一个文本文件,其中包含这种格式的数据。我要把医生的名字拿来。我可以知道正则表达式或任何其他处理这两种情况的方法是什么吗Regex 从同一行和下一行获取值,regex,python-3.x,data-extraction,Regex,Python 3.x,Data Extraction,我有一个文本文件,其中包含这种格式的数据。我要把医生的名字拿来。我可以知道正则表达式或任何其他处理这两种情况的方法是什么吗 The patient is referred by Dr. Zach Foster. The patient is referred by Dr. Corey Piccirillo Output: Dr. Zach Foster Dr. Corey Piccirillo 我在第一种情况下使用以下正则表达式,然后使用Spacy提取名称: re(r'.*refer
The patient is referred by Dr. Zach Foster.
The patient is referred by
Dr. Corey Piccirillo
Output:
Dr. Zach Foster
Dr. Corey Piccirillo
我在第一种情况下使用以下正则表达式,然后使用Spacy提取名称:
re(r'.*referred by.*',re.I)
对于第二种情况:
for line in file:
if "referred by" in line:
print(next(ifile, '').strip())
将在捕获组中匹配这两种情况。谢谢!我工作了,只是在[\n\s]之后添加了一个小的更新*,否则它与第二个案例不匹配,所以re(r'by[\n\s]*(Dr.+\.*),re.I)
re(r'by[\n\s](Dr.+\.*)',re.I)