I do not use Notepad ++ , I use UltraEdit , and therefore the regular expression below was tested only using the Perl UltraEdit regular expression engine.
\<(word1|word2)\>(?:[\t \S](?!\<\1\>))*?\<(?:word1|word2)\>
This regular expression first searches for either word1 OR word2 , which should be found as a complete word, and not as a substring inside a word, since \< means the beginning of the word, and \> means the end of the word. It is also possible to use \b (word boundary) instead of \< and \> .
If one of the two words is found in a string, it searches for the next for 0 or more characters, which are either a space character or any non-primary character that is not greedy. It is also possible to use . instead of the character class [\t \S] , if the default matching behavior for a point is any character except string terminators, which is true for UltraEdit to limit the search by string.
On each character of this line, a negative lookahead is applied between the two words, checking whether the following characters after the already matching character match the word found by the first OR expression. This additional condition avoids searching for strings containing only one of two words in an OR expression twice.
The last OR expression from the beginning is added a second time to the expression, but this time as a group without marking. Therefore, the search must match another word from the OR expression in order to return a positive result.
Mofi Jun 13 '14 at 5:59 a.m. 2014-06-13 05:59
source share