Regex-Python如何找到长度最小的字符串

Regex-Python如何找到长度最小的字符串,python,regex,Python,Regex,假设我们有下面的文本 Lorem Ipsum只是印刷和排版的虚拟文本 工业Lorem Ipsum一直是业界标准的虚拟文本 从16世纪开始,当一个不知名的印刷商在一个厨房里打印 把它拼凑成一本样本书。它不仅存活了下来 五个世纪,也是电子排版的飞跃, 基本保持不变。它在20世纪60年代开始流行 发布了包含Lorem Ipsum段落的Letraset表单,最近发布了Aldus等桌面出版软件 PageMaker包括Lorem Ipsum版本 我想在两个粗体字之间匹配文本 当我使用the.*Pagemak

假设我们有下面的文本

Lorem Ipsum只是印刷和排版的虚拟文本 工业Lorem Ipsum一直是业界标准的虚拟文本 从16世纪开始,当一个不知名的印刷商在一个厨房里打印 把它拼凑成一本样本书。它不仅存活了下来 五个世纪,也是电子排版的飞跃, 基本保持不变。它在20世纪60年代开始流行 发布了包含Lorem Ipsum段落的Letraset表单,最近发布了Aldus等桌面出版软件 PageMaker包括Lorem Ipsum版本

我想在两个粗体字之间匹配文本

当我使用
the.*Pagemaker
时,大部分文本从'the'的第一个实例匹配到
Pagemaker
,而不是从最接近它的
实例匹配


你能帮帮我吗?

试着在文章之前使用一些东西

import re
txt="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."

phrase_get=re.search(r'1960s with the.+PageMaker',txt)[0]
print(phrase_get)

这是一个棘手的问题-但我认为使用
消极前瞻
可能会奏效:

 the(?!.*the).*PageMaker
在这里,我们正在寻找一个以“the”开头,以“PageMaker”结尾的匹配项,但它本身并不通过
包含“the”操作员


签出以查看这是否适用于您。

我找到了“'the(?:(?!the)。*PageMaker'谢谢。它工作得非常好。您也可以使用贪婪搜索:'.*the(.*)PageMaker'