How to find multiple values on the same line in any permutation using Notepad++

notepadregex

I am using Notepad++, and I'm trying to find a way where I can search for multiple values on the same line. The regex search is not working for me currently, as I may not know which order the values are in.

For example, I want to search for a line of code which has three specific values. Using .* in the regex search is not working as you must know the order of the values. Is it possible for me to search for these lines without knowing the order of the values?

On each line I have perhaps a trading log which has 30 different tags.
I want to search for 35=D, EUR/USD, 150=8. I only want to search for entries with all three values present.

The issue I run into is that the order of these tags are not guaranteed, so the regex search I use below does not always find each entry I require.

35=D.*EUR/USD.*150=8

Best Answer

Using lookahead is much more efficient and can deal with any number of alternations without increasing complexity:

  • Ctrl+F
  • "Find what": ^(?=.*\b35=D\b)(?=.*\bEUR/USD\b)(?=.*\b150=8\b).+$
  • Check "Match case"
  • Check "Wrap around"
  • Check "Regular expression"
  • Uncheck ". matches newline"
  • Find All in Current Document

Explanation:

^               # Beginning of line
  (?=           # Start positive lookaead, make sure we have after:
    .*          # 0 or more any character but newline
    \b          # Word boundary to be sure not matching 135=DATA
    35=D        # Literally
    \b          # word boundary
  )             # End lookahead
  (?=           # Start positive lookaead, make sure we have after:
    .*          # 0 or more any character but newline
    \b          # Word boundary
    EUR/USD     # Literally
    \b          # Word boundary
  )             # End lookahead
  (?=           # Start positive lookaead, make sure we have after:
    .*          # 0 or more any character but newline
    \b          # Word boundary
    150=8       # Literally
    \b          # Word boundary
  )             # End lookahead
  .+            # One or more any character but newline
$               # End of line

Screen capture:

Enter image description here

Related Question