Search code examples
regexsearchlinecpu-word

Regex, how to find lines that contain both specified words?


how to find lines that contain both specified words - using Regex pattern?

For example, I need find lines, than contains both words 'MExp' and 'Aggregate'.

Thank you.


Solution

  • Let's say you have a file.

    abcde
    fghijk MExp lmnopq Aggregate
    fghijk MExp Aggregate lmnopq 
    fghijk Aggregate lmnopq MExp 
    fghijk Aggregate MExp lmnopq  
    xywz
    

    If the order of the words are not relevant, the regex would be

    (MExp.*Aggregate)|(Aggregate.*MExp)

    If the order is important, use only the applicable one.

    MExp.*Aggregate or Aggregate.*MExp