import re
word_one = "networks"
word_two = "researchers"
string = "There are thousands of types of specific networks proposed by researchers as modifications or tweaks to existing models"
result = re.search(f'{word_one}(.+?){word_two}', string)
print(result.group(1))
text = "There are thousands of types of specific networks proposed by researchers as modifications or tweaks to existing models"
word1 = "networks"
word2 = "researchers"
start = text.find(word1)
end = text.find(word2)
if start != -1 and end != -1 and start < end:
print(text[start + len(word1):end])
你可以用正则表达式匹配这两个词
汤姆的回答更清楚。这是我的答案,不需要额外的库
找到每个单词的位置,然后使用这些位置提取它
相关问题 更多 >
编程相关推荐