I need help matching the two words "hello" and "hope" in mystring, but only counting the first occurrence in the string. The max distance they could be from each other is 5 words. Appreciate any help!
mystring = "hello bob nice weather hope you have a good day. hello jan hope weather is nice"
This is what I have so far. I'm wanting the result to only catch the first occurrence of "hello" and "hope" and stop matching afterwards.
pattern = re.findall('\bhello(?:\W+\w+){0,5}\W+hope\b', mystring)