Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to find files without newline at the end in IntellliJ

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?

like image 965
Michal Kordas Avatar asked Apr 06 '16 11:04

Michal Kordas


People also ask

How do you match a character including newline in regex?

By default in most regex engines, . doesn't match newline characters, so the matching stops at the end of each logical line. If you want . to match really everything, including newlines, you need to enable "dot-matches-all" mode in your regex engine of choice (for example, add re. DOTALL flag in Python, or /s in PCRE.

How do I check if a regex is valid in IntelliJ?

Choose Check RegExp, and press Enter. The dialog that pops up, shows the current regular expression in the upper pane. In the lower pane, type the string to which this expression should match. If the regular expression matches the entered string, IntelliJ IDEA displays a green check mark against the regex.

How do I know if a file contains a newline character?

A file that contains a contains one non-empty line. So a file that ends with at least one empty line ends with two newline characters or contains a single newline character. Outputs or , then the file contains at least one trailing empty line.

How do you match the end of a line in regex?

Line Anchors In regex, anchors are not used to match characters. Rather they match a position i.e. before, after, or between characters. To match start and end of line, we use following anchors: Caret (^) matches the position before the first character in the string. Dollar ($) matches the position right after the last character in the string. 2.

What is \n character in regex Perl?

Perl 5.12 introduced an experimental regex character class to stand in for every character except one, the newline. The \N character class is everything but the newline. In prior versions of Perl, this is the same thing as the . meta character.


Video Answer


1 Answers

Try small z: [^\n]\z

More on this here.

like image 81
Tamas Rev Avatar answered Sep 22 '22 03:09

Tamas Rev