Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 从同一行和下一行获取值_Regex_Python 3.x_Data Extraction - Fatal编程技术网

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)