in reply to and or statement

One strategy that often works well is to write a regex that will match any of the words desired (hint:   don’t forget the \b escape to match end-of-word), then push each word as-found onto a queue.

After finding a word, examine the top n entries in the list to see if the desired sequence has been found.   If so, shift off all of the words.

If the total size of the stack exceeds the number of words sought, shift off and discard words to make room, taking care always to be manipulating the front of the stack (oldest entries).