The |
operator is for alternation; it means “match this or that”. In your example that means you’re telling it to match a line that starts with WORD_1, WORD_2 or WORD_3. Not only is it matching them even if they’re not consecutive, it would also match them if they’re out of order or appear multiple times.
The +
operator means “match the thing that comes before me one or more times” (as opposed to *
which means "match the thing that comes before me zero or more times). In your example you’re telling it to find the words WORD_1, WORD_2 and WORD_3 all together (with nothing in between them), where each one can appear multiple times, but they have to appear in that order.
Something like this will do what you want (more or less, see below):
(?s)(^.*)WORD_1.*(^.*)WORD_2.*(^.*)WORD_3(.*)^
This works because the (?s)
part is telling the regex engine that the .
character should also match a newline character because normally it does not. The rest of the example is similar to what you tried originally.
Notice that we no longer include any $
characters because they don’t mean anything anymore; we are telling the system that the .
matches a newline, so there is no more “end of line” for the $
to match.
The regex ends with the ^
character for this reason. If you leave it off, the regex will match everything else to the end of the file. Adding in the ^
at the end stops the match when it gets to the start of the next line.
This means that if this sequence appears as the last 3 lines in the file, the regex will no longer match.
In theory your original example would word if you removed the |
characters and added (?m)
to the start of the regex to tell the regex engine that it should treat the input as multiple lines. However, Sublime doesn’t seem to honor that, so it doesn’t work here.