3

I have a list of words:

  • Alpha
  • Beta
  • Charlie
  • Delta
  • Echo

And a list of 1000 multi-line files. One or more of these files contains all 5 of the words, the others contain 4 or fewer. The words can appear in the files in any order. However, each word only appears once in each file.

I need to find the one or more files which contain all 5 words.

I am trying lots of regex to plug into "find in files" in notepad++ but I cannot make it work. Trying for one hour now.

1 Answer 1

4
  • Ctrl+Shift+H
  • Find what: \A(?=.*\bAlpha\b)(?=.*\bBeta\b)(?=.*\bCharlie\b)(?=.*\bDelta\b)(?=.*\bEcho\b)
  • CHECK Match case
  • CHECK Regular expression
  • CHECK . matches newline
  • Find All

Explanation:

\A                      # beginning of file
(?=                     # positive lookahead, make sure we have after:
    .*                      # 0 or more any character
    \b                      # word boundary
    Alpha                   # word to search
    \b                      # word boundary
)                       # end lookahead
(?=.*\bBeta\b)          # same for 2nd word
(?=.*\bCharlie\b)       # same for 3rd word
(?=.*\bDelta\b)         # ...
(?=.*\bEcho\b)          # ...

This makes sure we have all the 5 words in any order in the files.

Screenshot:

enter image description here

2
  • Awesome that works thank you!! Jan 16, 2021 at 12:01
  • @tomredfern: You're welcome, glad it helps.
    – Toto
    Jan 16, 2021 at 12:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .