import re
string = 'adverb with text verb text from here on'
print re.findall(r'adverb(.*?)verb', string)
它打印出这个:
^{pr2}$
编辑:
如果您还想获得noun,请使用以下命令:
import re
string = [
'adverb with text verb text from here on',
'adverb with text noun text from here on'
]
print [re.findall(r'adverb(.*?)(?:verb|noun)', s) for s in string]
你的正则表达式应该是这样的:
当然,您可以使用
re.search()
。。它打印出这个:
^{pr2}$编辑:
如果您还想获得
noun
,请使用以下命令:现在你有了:
^{4}$相关问题 更多 >
编程相关推荐