我正在尝试使用Python编写一个正则表达式,以匹配包含特定单词的单个句子(从.
到.
)。
我写的正则表达式是r"\..*?hello.*?\."
。如您所见,我正在使用非贪婪量词。
我要匹配的文本是:
This is the 1st sentence. This is the 2nd. This is the 3rd, hello, world. This is the 4th.
(这是regex101的link)
我希望匹配为This is the 3rd, hello, world.
,但是尽管*?
量词是非贪婪的,但匹配项还包括第二句。我想念什么?