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))
Tom's answer is cleaner. Here is my answer without additional libraries
Find the locations of each word, then use those locations to extract it
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])
Rakesh's answer is cleaner. Here is my answer without additional libraries
Find the locations of each word, then use those locations to extract it.
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])