标签: python
我希望能够在我选择的单词之间插入字符串。例如:
x = "Hello My Name is John Doe"
我希望程序返回一个字符串,其中包含Hello和Doe之间的值 - "My Name is John "
"My Name is John "
提前致谢!
答案 0 :(得分:1)
import re x = re.search("Hello (.*)Doe", "Hello My Name is John Doe") if x: print x.groups()[0]