
The second change is that I am doing the alternate for the full row instead of making an alternate for just the end-of-line section, and allowing a newline followed by 0 or more spaces followed by the end of the file as another match. This makes the simplification of using third expression, but without the group wrapper or the + quantifier, because matching one blank line and doing replace all does the same as matching multiple blank lines and doing replace all. So for the most generic version, which will work at the end of the file, use ^\h*\R|\R\h*\z. … This is because the character(s) that need to be deleted are actually the previous newline, and aren’t part of the “last” line at all. However, I will say that if your next-to-last line has text and newline but your last line is empty (no newline), it won’t delete that truly empty line: it will just keep looking like this every time you hit replace: Note that the second instances (my regular expressions) in each of those bullet points will work identically as for all lines that end in newlines, but will also allow them to work on lines at the end of the file that are missing newlines. For empty or blank lines that might not have a newline because it’s the end of the file, use ^(\h*(\R|\Z))+

For blank lines that might not have a newline because it’s the end of the file, use ^(\h+(\R|\Z))+

) ensures that the two-chars sequence \r\n cannot be separated, even in case of backtracking, in order to match further parts of the overall regex ).The \h ( horizontal blank character class ) = [\t\x20\xA0\x) ( The atomic syntax (?>
