Reputation: 10925
I'm trying to find all files without line feed character at the end of file using Find in Files menu in IntelliJ IDEA.
I've tried regex [^\n]\Z
, but it also finds files with newlines.
What is proper regexp to do that? Or maybe there's other way to accomplish this?
Upvotes: 13
Views: 3457
Reputation: 626926
The $
anchor conforms to the $
Perl-like behavior matching at the end of the sting or before the last \n
in the string. You can still use the $
, but restrict the end of the string with a negative lookahead.
[^\n]$(?!\n)
See the regex demo
Since $
may match at the end of the string, but also before the last LF, the (?!\n)
lookahead makes sure to fail the match if an LF is the last character in the string.
Upvotes: 2