When you want to make the search efficient you have to be aware of the different goals: The Eclipse Search function looks for all occurrences but you want to check for the presence of a word only.
For a single word you can just search for word
but since you want to search for combinations using unbounded quantifiers this does not perform very well.
So the first thing you have to do is to stop Eclipse (the regex engine) from checking for a match at every character position of a file by adding the anchor \A
which stands for “beginning of the file”. Then skip as little characters as possible and search for a literal word match to check for the presence:
(?s)\A.*?word
will search for the first occurrence of word
but not for any further.
Expanding it to check for two words in order is easy:
(1) (?s)\A.*?word1.*?word2
Just checks for one occurrence of each word in order but nothing more.
For checking of the presence or absence without an order you can use a look-ahead:
(2) (?s)\A(?!.*?word2).*?word1
Simply negate the look-ahead to tell that word2
must not be present…
(3) (?s)\A(?=.*?word1).*?word2
If one match for word1
is present find one match for word2
; of course, word1
and word2
are interchangeable.
(4) (?s)\A(?!.*?word1).?
and just use the negative look-ahead to search for the absence of word1
only; if absent .?
just matches a single optional character as an empty regex won’t match anything in DOTALL
mode.
(5) (?s)\A.*?(word1|word2)
Telling that either word1
or word2
satisfies is straight-forward.
Of course, if you are looking for whole words, the word
placeholders above have to be replaced by \bactualwordcharacters\b
.