删除记事本中的空行++
如何替换 Notepad++ 中的空行?我尝试查找并替换查找中的空行,替换中没有任何内容,但它不起作用;它可能需要正则表达式。
How can I replace empty lines in 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(22)
从版本 6.5.2 开始,现在有一种内置方法可以执行此操作
Edit ->线路操作->删除空行
或删除空行(包含空白字符)
There is now a built-in way to do this as of version 6.5.2
Edit -> Line Operations -> Remove Empty Lines
orRemove Empty Lines (Containing Blank characters)
你需要像正则表达式这样的东西。
您必须处于
扩展
模式如果您希望所有行都以单行结束,请使用
\r\n< /代码>。如果您只想删除空行,请使用
\n\r
,如@Link最初建议的那样。将任一表达式替换为空。
You need something like a regular expression.
You have to be in
Extended
modeIf you want all the lines to end up on a single line use
\r\n
. If you want to simply remove empty lines, use\n\r
as @Link originally suggested.Replace either expression with nothing.
有一个插件可以添加一个名为
TextFX
的菜单。该菜单包含一系列令人眼花缭乱的快速文本编辑选项,使人们能够快速更改编码。在此菜单中,您可以找到诸如“删除引号”、“删除空白行”以及“展开和重新包装文本”等选项执行以下操作:
There is a plugin that adds a menu entitled
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 TextDo the following:
^[ \t]*$\r?\n
,将替换留空。这将匹配所有以空格开头并以回车符结尾的行(在本例中为 windows crlf)^[ \t]*$\r?\n
into find what, leave replace empty. This will match all lines starting with white space and ending with carriage return (in this case a windows crlf)^\R
(对于精确的空行)或^\h*\R
(对于带有空格的空行) , 仅有的)。^\R
( for exact empty lines) or^\h*\R
( for empty lines with blanks, only).您可以按照以下屏幕截图所示的方法进行操作:
^\r\n
将其留空
正则表达式
注意:对于 *nix 文件只需通过
\n
查找You can follow the technique as shown in the following screenshot:
^\r\n
keep this empty
Regular expression
NOTE: for *nix files just find by
\n
这对我有用:
ctrl + h
(替换快捷键)查找内容
框中写入以下正则表达式之一。[\n\r]+$
或^[\n\r]+
替换为
框留空搜索模式< < /code>,选择
Regex
全部替换
完毕!
This worked for me:
ctrl + h
(Shortcut for replace)find what
box.[\n\r]+$
or^[\n\r]+
Replace with
box blankSearch Mode
, selectRegex
Replace All
Done!
1)
Ctrl + H
(或Search
1)
Ctrl + H
( OrSearch ???? Replace..
) to open Replace window.2) Select
'Search Mode'
'Regular expression'3) In 'Find What' type
^(\s*)(.*)(\s*)$
& in 'Replace With' type\2
^
- Matches start of line character(\s*)
- Matches empty space characters(.*)
- Matches any characters(\s*)
- Matches empty spaces characters$
- Matches end of line character\2
- Denotes the matching contend of the 2nd bracketRefer https://www.rexegg.com/regex-quickstart.html for more on regex.
在记事本++中按 CTRL+H ,在搜索模式下单击“扩展(\n,\r,\t ...)”单选按钮,然后在“查找内容”框中键入:\r\n(CR LF 的缩写) )并将“替换为”框留空。
最后点击全部替换
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..
Finally hit replace all
您可以搜索以下正则表达式:
^(?:[\t ]*(?:\r?\n|\r))+
并将其替换为空字段You can search for the following regex:
^(?:[\t ]*(?:\r?\n|\r))+
and replace it with empty field好吧,我不确定正则表达式或您的情况。
如何 CTRL+A,选择 TextFX 菜单 -> TextFX 编辑 ->删除空白行,中提琴所有空白行都消失了。
附注 - 如果该行为空,即不包含空格,这将起作用
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.
A side note - if the line is blank i.e. does not contain spaces, this will work
Ctrl+H。
查找 - \r\r
替换为 - \r。
Ctrl+H.
find - \r\r
replace with - \r.
如果空行包含制表符或空格,这显然不起作用。许多网页(例如 http://www.guardian.co.uk/)包含这些白线,由于 HTML 编辑器错误而导致。
使用正则表达式删除空格,如下所示:
其中 [\t ] 匹配制表符或空格。 '+' 匹配一个或多个匹配项,'$' 标记行结束。
然后使用 notepad++/textFX 删除单个或多余的空行。
确保这些空行在给定上下文中并不重要。
This obviously does not work if the blank lines contain tabs or blanks. Many web pages (e.g. http://www.guardian.co.uk/) contain these white lines, as a result of a faulty HTML editor.
Remove white space using regular expression as follows:
where [\t ] matches either tab or space. '+' matches one or more occurrences, and '$' marks the end of line.
Then use notepad++/textFX to remove single or extra empty lines.
Be sure that these blank lines are not significant in the given context.
有时 \n\r 等不起作用,在这里弄清楚你的实际正则表达式应该是什么。
这个技巧的优点:如果你想一次替换多个文件,你必须需要这个方法。上面不行...
Sometimes \n\r etc not work, here to figure it out, what your actually regular expression should be.
Advantage of this trick: If you want to replace in multiple file at once, you must need this method. Above will not work...
此模式在 Notepad++ v8.1.1 中进行了测试,
它替换了每行文本之前和之后的所有空格/制表符/空白行。
它不应该扰乱文本中间的任何内容。
This pattern is tested in Notepad++ v8.1.1
It replaces all
spaces/tabs/blank lines
before and after each row of text.It shouldn't mess with anything in the middle of the text.
^\r\n< /code> 不包含任何内容(选择正则表达式)
注意:第 1 步将删除通过制表符和空格完成的代码意图
^\r\n
with nothing (select regular expression)Note: step 1 will remove your code intendation done via tabs and blank spaces
CTRL+A,选择TextFX菜单-> TextFX 编辑 ->按照上面的建议删除空白行。
但如果行包含一些空格,则将光标移动到该行并执行 CTRL + H。“查找内容:”秒将显示空格,并在“替换为”部分中将其留空。
现在所有空格都已删除,现在尝试 CTRL+A,选择 TextFX 菜单 -> TextFX 编辑 ->删除空行
CTRL+A, Select the TextFX menu -> TextFX Edit -> Delete Blank Lines as suggested above works.
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.
Now all the spaces are removed and now try CTRL+A, Select the TextFX menu -> TextFX Edit -> Delete Blank Lines
/n/r
假定特定类型的换行符。要定位任何空白行,您还可以使用:这表示 - 任何开始和结束之间没有任何内容的行。这更像是一个包罗万象的东西。替换为相同的空字符串。
/n/r
assumes a specific type of line break. 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.
我没有看到合并后的答案,因此搜索 ^\s+$ 并替换为 {nothing}
I did not see the combined one as answer, so search for ^\s+$ and replace by {nothing}
上面的一些表达式和扩展表达式对我不起作用,但正则表达式“$\n$”对我有用。
A few of the above expressions and extended expressions did not work for me, but the regular expression "$\n$" did.
从空行中删除空格的简单替代方法:
这将删除所有尾随空格,包括空行中的尾随空格。
确保尾随空格不重要。
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: