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 使用python仅从文本中提取指定值_Regex_Python 3.x_Spacy_Data Extraction - Fatal编程技术网

Regex 使用python仅从文本中提取指定值

Regex 使用python仅从文本中提取指定值,regex,python-3.x,spacy,data-extraction,Regex,Python 3.x,Spacy,Data Extraction,我有一个包含以下数据的文本文件。我必须提取所有包含签名的行 The document was signed on July 12 The document was signed by Charlie This document was assigned to John The document was preassigned to Amanda 预期产出: The document was signed on July 12 The document was signed by Cha

我有一个包含以下数据的文本文件。我必须提取所有包含签名的行

The document was signed on July 12

The document was signed by Charlie

This document was assigned to John

The document was preassigned to Amanda
预期产出:

The document was signed on July 12

The document was signed by Charlie
如果我正在使用:

for line in file:
    if "signed" in line:
        print (line)

它正在打印所有行

这可以通过使用单词边界
\b
轻松完成\b已签名将匹配已签名,但未分配


您可以使用
re.search(行“.*\b已签名。*”)

谢谢!我对regex不熟悉。我研究了单词的边界,但并没有想到它。再次感谢你!是的,它类似于你发布的重复链接,但我不会通过引用该示例来解决它,因为我是新的正则表达式