Regex to search for files without a new line at the end of IntellliJ

I am trying to find all files without a line symbol at the end of the file using the Find Files menu in IntelliJ IDEA.

I tried regex [^\n]\Z , but it also finds files with newlines.

What is the correct regular expression for this? Or maybe there is another way to do this?

+6
source share
2 answers

Try a little z: [^\n]\z

Read more about it here .

+10
source

The $ anchor corresponds to a $ matching behavior similar to Perl at the end of a bite or before the last \n in a string. You can still use $ , but limit the end of the line to a negative lookup.

 [^\n]$(?!\n) 

Watch the regex demo

Since $ can match at the end of a line, but also before the last LF, looking at (?!\n) ensures that it does not match if LF is the last character in the line.

+2
source

All Articles