[英]Removing empty lines in Notepad++
How can I replace empty lines in Notepad++?如何替换 Notepad++ 中的空行? I tried a find and replace with the empty lines in the find, and nothing in the replace, but it did not work;
我尝试了查找并用查找中的空行替换,替换中没有任何内容,但是没有用; it probably needs regex.
它可能需要正则表达式。
You need something like a regular expression.你需要像正则表达式这样的东西。
You have to be in Extended
mode您必须处于
Extended
模式
If you want all the lines to end up on a single line use \r\n
.如果您希望所有行都在一行中结束,请使用
\r\n
。 If you want to simply remove empty lines, use \n\r
as @Link originally suggested.如果您只想删除空行,请按照@Link 最初建议的那样使用
\n\r
。
Replace either expression with nothing.将任一表达式替换为空。
There is a plugin that adds a menu entitled TextFX
.有一个插件可以添加一个名为
TextFX
的菜单。 This menu, which houses a dizzying array of quick text editing options, gives a person the ability to make quick coding changes.这个菜单包含一系列令人眼花缭乱的快速文本编辑选项,使人们能够快速更改代码。 In this menu, you can find selections such as Drop Quotes, Delete Blank Lines as well as Unwrap and Rewrap Text
在此菜单中,您可以找到诸如删除引号、删除空行以及展开和重新包裹文本等选项
Do the following:请执行下列操作:
TextFX > TextFX Edit > Delete Blank Lines
TextFX > TextFX Edit > Delete Surplus Blank Lines
^[ \t]*$\r?\n
into find what, leave replace empty.^[ \t]*$\r?\n
,将替换留空。 This will match all lines starting with white space and ending with carriage return (in this case a windows crlf)^\R
( for exact empty lines) or ^\h*\R
( for empty lines with blanks, only).^\R
(对于精确的空行)或^\h*\R
(仅对于带空格的空行)。You can follow the technique as shown in the following screenshot:您可以按照以下屏幕截图中所示的技术进行操作:
^\r\n
^\r\n
keep this empty
keep this empty
Regular expression
Regular expression
NOTE: for *nix files just find by \n
注意:对于 *nix 文件,只需通过
\n
查找
This worked for me:这对我有用:
ctrl + h
(Shortcut for replace)ctrl + h
(替换快捷键)find what
box.find what
框中编写以下正则表达式之一。 [\n\r]+$
or ^[\n\r]+
[\n\r]+$
或^[\n\r]+
Replace with
box blank Replace with
框留空Search Mode
, select Regex
Search Mode
中,选择Regex
Replace All
Replace All
In notepad++ press CTRL+H, in search mode click on the "Extended (\n, \r, \t...)" radio button then type in the "Find what" box: \r\n (short for CR LF) and leave the "Replace with" box empty..在记事本++中按 CTRL+H,在搜索模式下单击“扩展(\n、\r、\t...)”单选按钮,然后在“查找内容”框中键入:\r\n(CR LF 的缩写) ) 并将“替换为”框留空。
Finally hit replace all最后点击全部替换
Well I'm not sure about the regex or your situation..好吧,我不确定正则表达式或您的情况..
How about CTRL+A, Select the TextFX menu -> TextFX Edit -> Delete Blank Lines and viola all blank line gone. CTRL+A 怎么样,选择 TextFX 菜单 -> TextFX 编辑 -> 删除空行,中提琴所有空行都消失了。
A side note - if the line is blank ie does not contain spaces, this will work旁注 - 如果该行是空白的,即不包含空格,这将起作用
1) Ctrl + H
( Or Search Replace..
) to open Replace window. 1)
Ctrl + H
(或Search Replace..
)打开替换窗口。
2) Select 'Search Mode'
'Regular expression' 2) 选择
'Search Mode'
“正则表达式”
3) In 'Find What' type ^(\s*)(.*)(\s*)$
& in 'Replace With' type \2
3) 在“查找内容”中键入
^(\s*)(.*)(\s*)$
并在“替换为”中键入\2
^
- Matches start of line character ^
- 匹配行首字符(\s*)
- Matches empty space characters (\s*)
- 匹配空格字符(.*)
- Matches any characters (.*)
- 匹配任何字符(\s*)
- Matches empty spaces characters (\s*)
- 匹配空格字符$
- Matches end of line character $
- 匹配行尾字符\2
- Denotes the matching contend of the 2nd bracket \2
- 表示第二个括号的匹配竞争 Refer https://www.rexegg.com/regex-quickstart.html for more on regex.
有关正则表达式的更多信息,请参阅https://www.rexegg.com/regex-quickstart.html 。
You can search for the following regex: ^(?:[\t ]*(?:\r?\n|\r))+
and replace it with empty field您可以搜索以下正则表达式:
^(?:[\t ]*(?:\r?\n|\r))+
并将其替换为空字段
How can I replace empty lines in Notepad++?如何替换 Notepad++ 中的空行? I tried a find and replace with the empty lines in the find, and nothing in the replace, but it did not work;
我尝试了查找并替换为查找中的空行,而替换中没有任何内容,但是没有用; it probably needs regex.
它可能需要正则表达式。
Ctrl+H. Ctrl+H。
find - \r\r replace with - \r.查找 - \r\r 替换为 - \r。
This obviously does not work if the blank lines contain tabs or blanks.如果空白行包含制表符或空格,这显然不起作用。 Many web pages (eg http://www.guardian.co.uk/ ) contain these white lines, as a result of a faulty HTML editor.
许多网页(例如http://www.guardian.co.uk/ )包含这些白线,这是错误的 HTML 编辑器的结果。
Remove white space using regular expression as follows:使用正则表达式删除空格,如下所示:
change pattern: [\t ]+$ into nothing.
改变 pattern: [\t ]+$ 为空。
where [\t ] matches either tab or space.其中 [\t ] 匹配制表符或空格。 '+' matches one or more occurrences, and '$' marks the end of line.
'+' 匹配一次或多次出现,'$' 标记行尾。
Then use notepad++/textFX to remove single or extra empty lines.然后使用记事本++/textFX 删除单个或额外的空行。 Be sure that these blank lines are not significant in the given context.
确保这些空白行在给定上下文中不重要。
^\r\n
with nothing (select regular expression) ^\r\n
什么都没有(选择正则表达式) Note: step 1 will remove your code intendation done via tabs and blank spaces注意:第 1 步将删除通过制表符和空格完成的代码意图
Sometimes \n\r etc not work, here to figure it out, what your actually regular expression should be.有时 \n\r 等不起作用,在这里弄清楚,你的实际正则表达式应该是什么。
Advantage of this trick: If you want to replace in multiple file at once, you must need this method.这个技巧的好处:如果你想一次替换多个文件,你必须用这个方法。 Above will not work...
以上无效...
CTRL+A, Select the TextFX menu -> TextFX Edit -> Delete Blank Lines as suggested above works. CTRL+A,选择 TextFX 菜单 -> TextFX 编辑 -> 删除空行,如上所示。
But if lines contains some space, then move the cursor to that line and do a CTRL + H. The "Find what:" sec will show the blank space and in the "Replace with" section, leave it blank.但是,如果行中包含一些空格,则将光标移动到该行并执行 CTRL + H。“查找内容:”秒将显示空格,并在“替换为”部分中将其留空。 Now all the spaces are removed and now try CTRL+A, Select the TextFX menu -> TextFX Edit -> Delete Blank Lines
现在所有空格都被删除,现在尝试 CTRL+A,选择 TextFX 菜单 -> TextFX 编辑 -> 删除空行
/n/r
assumes a specific type of line break. /n/r
假定特定类型的换行符。 To target any blank line you could also use:要定位任何空白行,您还可以使用:
^$
This says - any line that begins and then ends with nothing between.这表示 - 任何开始和结束之间没有任何内容的行。 This is more of a catch-all.
这更像是一个包罗万象的。 Replace with the same empty string.
替换为相同的空字符串。
I did not see the combined one as answer, so search for ^\s+$ and replace by {nothing}我没有看到合并的答案,所以搜索 ^\s+$ 并替换为 {nothing}
^\s+$ means
^ start of line
\s+ Matches minimum one whitespace character (spaces, tabs, line breaks)
$ until end of line
This pattern is tested in Notepad++ v8.1.1此模式已在 Notepad++ v8.1.1 中测试
It replaces all spaces/tabs/blank lines
before and after each row of text.它会替换每行文本前后的所有
spaces/tabs/blank lines
。
It shouldn't mess with anything in the middle of the text.它不应该混淆文本中间的任何内容。
Find: ^(\s|\t)+|(\s|\t)+$
Replace: leave this blank
Before:
_____________________________________
\tWORD\r\n
\r\n
\tWORD\s\tWORD\s\t\r\n
\r\n
\r\n
WORD\s\s\tWORD\t\sWORD\s\r\n
\t\r\n
\s\s\s\r\n
WORD\s\sWORD\s\s\t\r\n
____________________________________
After:
_____________________________________
WORD\r\n
WORD\s\tWORD\r\n
WORD\s\s\tWORD\t\sWORD\r\n
WORD\s\sWORD
_____________________________________
A few of the above expressions and extended expressions did not work for me, but the regular expression "$\n$" did.上面的一些表达式和扩展表达式对我不起作用,但正则表达式“$\n$”对我有用。
An easy alternative for removing white space from empty lines:从空行中删除空格的简单替代方法:
This will remove all trailing spaces, including trailing spaces in blank lines.这将删除所有尾随空格,包括空白行中的尾随空格。 Make sure, no trailing spaces are significant.
确保没有重要的尾随空格。
this work for me:这对我有用:
SEARCH:^\r
REPLACE: (empty)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.