Notepad ++中的正则表达式删除空行

Mik*_*ike 4 regex replace notepad++

我有多个html文件,其中一些有一些空行,我需要一个正则表达式删除所有空白行,只留下一个空白行..所以它删除任何多于一个空白行,并留下那些只是一个或没有(没有人喜欢在其中加入文字).

我还需要它来考虑不完全空白的行,因为有些行可能有空格或制表符(没有显示的字符),所以我需要它考虑这些行与正则表达式被删除只要它更多比一行..

Tim*_*ker 9

搜索

^([ \t]*)\r?\n\s+$
Run Code Online (Sandbox Code Playgroud)

并替换为

\1
Run Code Online (Sandbox Code Playgroud)

说明:

^         # Start of line
([ \t]*)  # Match any number of spaces or tabs, capture them in group 1
\r?\n     # Match one linebreak
\s+       # Match any following whitespace
$         # until the last possible end of line.
Run Code Online (Sandbox Code Playgroud)

\1 然后将包含第一行空格字符,因此当您使用它作为替换字符串时,只保留第一行空格(不包括末尾的换行符).


小智 9

这对我有用 notepad++ v6.5.1. UNICODE windows 7

搜索: ^[ \t]*\r\n

替换为:没有,留空

搜索模式: Regular expression.