Search code examples
regexnotepad++

Regular expression for a file that does not have a line that starts with a specific word


I want to search the entire file not just a line. ^((?!MYWORD).)*$ this will search if I understand correct the line does not start with the word "MYWORD" providing "." excludes newlines of course. So I want to check there is no line at all like this on any line in the file.

So if my file contains:

xyz
MYWORD is here
123

Then I exclude this file.

Note I am typing my regular expression in the Find in Files dialog of NotePad++ (v7.9.1) where I specify a folder so I want to search all files in folder.

enter image description here

Practical example find files that don't have a "CREATE" clause in .sql files.

I know someone smart will say use an expression that finds the MYWORD you want then you can eliminate these, but you know I want to know if it is possible.


Solution

  • If you want to find files that do not contain CREATE you could use this pattern in the Find in Files tab:

    (?s)\A(?!.*\bCREATE\b)
    
    • (?s) Inline modifier, dot matches a newline
    • \A Start of string
    • (?!.*\bCREATE\b) Assert not the word CREATE in the text using word boundaries \b

    Regex demo

    enter image description here