【发布时间】:2021-07-25 17:59:39
【问题描述】:
我想从以下字符串中提取“Bar”:
FooFooFoo the FooFoo the Bar Foo
FooFooFoo the FooFoo my Bar Foo
但我写的正则表达式 (the|my) (?P<bar>.+?) Foo 似乎太贪心了,收集的文本比需要的多 (example at regex101.com)
edit:“Bar”是要匹配的示例字符串。在我的真实案例场景中,我可以由多个单词组成。
我做错了什么?谢谢!
我需要使用标准的 re python 库来运行它。
【问题讨论】:
标签: python regex python-re regex-greedy