【发布时间】:2017-09-30 22:54:58
【问题描述】:
我有一个字符串,可以通过以下方式说明(额外的空格):
"words that don't matter START some words one some words two some words three END words that don't matter"
为了获取 START 和 END ['some words one', some words two', 'some words three'] 之间的每个子字符串,我编写了以下代码:
result = re.search(r'(?<=START).*?(?=END)', string, flags=re.S).group()
result = re.findall(r'(\(?\w+(?:\s\w+)*\)?)', result)
是否有可能用一个正则表达式来实现这一点?
【问题讨论】: