简体   繁体   English

使用记事本++从包含段落的文本文件中删除LAST空行

[英]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++? 如何使用Regx和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. 我以为“环视”正则表达式可能有效,例如:(?s)(?=。*)\\ n,但它似乎找到了所有行尾字符,而不是最后一个字符。

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 由于\\R\ \ |[\ \ \ \ \…\
\
] ,因此您也可以使用

(?:\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: 或者,如果不支持\\z

(?:\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. $(?![\\s\\S])匹配行/字符串的末尾,且不允许使用char。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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