简体   繁体   中英

Remove LAST blank line from a text file containing paragraphs using notepad++

How to remove the last blank line from the following example using a Regx and notepad++?

qwerty
asdfgh
<blank line>
zxcvbn
poiuyr
<last blank line>

The text example contains blank lines between the blocks of text.

I thought a 'lookaround' regx might work, for example: (?s)(?=.*)\\n, but it seems to find all end of line characters and not the last one.

You may use a generic

\R\z

It will match a linebreak and the end of file.

Depending on your file line break style, you may use

\r\n\z
\r\z
\n\z
\r?\n\z

As \\R is a shorthand for \ \ |[\ \ \ \ \…\
\
] , you may also use

(?:\u000D\u000A|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029])\z
(?:\x{000D}\x{000A}|[\x{000A}\x{000B}\x{000C}\x{000D}\x{0085}\x{2028}\x{2029}])\z

Or, if \\z is not supported:

(?:\u000D\u000A|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029])$(?![\s\S])
(?:\x{000D}\x{000A}|[\x{000A}\x{000B}\x{000C}\x{000D}\x{0085}\x{2028}\x{2029}])$(?![\s\S])

The $(?![\\s\\S]) matches end of a line/string with no char after it allowed.

尝试使用此\\n\\Z删除所有空的las行,如果只需要一个,请尝试\\n\\z

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM