I have a requirement where I am looking for the words "house" and "car" but they have to be within 10 words of each other. I have the following regular expression:
(\b(?=.*[a-zA-Z])(?i)car\b)|(\b(?=.*[a-zA-Z])(?i)house\b)
This works well with any combination of words. However, this doesn't satisfy the "within 10 words of each other" requirement:
Hence, the following would be a good match:
car word1 word2 word3 word4 word5 word6 word7 word8 word9 word10 house
house word1 word2 word3 word4 word5 word6 word7 word8 word9 word10 car
However the following shouldn't be a match:
house word1 word2 word3 word4 word5 word6 word7 word8 word9 word10 word 11 car
car word1 word2 word3 word4 word5 word6 word7 word8 word9 word10 word 11 house
How can I accomplish this? Thanks in advance.