Hope I can explain this.
I have a regex for matching two words side by side. For example, if I want to find the word "account" and "number" within 5 words of each other:
\ baccount \ W + (?: \ W + \ W +)? {1,6} the number \ b
This works great.
Now I need to find a way to search for a word until it is within 2 words of another word.
For example, I need a regular expression that matches "Butthead", but only if "Beavis" is not within 2 words, either before or after Butthead.
So Butthead and Beavis are not the same. Beavis and Butthead do not match. But Beavis Sure Giant Butthead will match, because Beavis and Butthead are NOT 2 words.
Jason source share