删除记事本中的空行++

发布于 2024-09-26 08:42:52 字数 70 浏览 8 评论 0原文

如何替换 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(22

温馨耳语 2024-10-03 08:42:52

从版本 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 or Remove Empty Lines (Containing Blank characters)

Screenshot of removing empty lines

冷情 2024-10-03 08:42:52

你需要像正则表达式这样的东西。

您必须处于扩展模式

如果您希望所有行都以单行结束,请使用\r\n< /代码>。如果您只想删除行,请使用\n\r,如@Link最初建议的那样。

将任一表达式替换为空。

You need something like a regular expression.

You have to be in Extended mode

If 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.

挽容 2024-10-03 08:42:52

有一个插件可以添加一个名为 TextFX 的菜单。该菜单包含一系列令人眼花缭乱的快速文本编辑选项,使人们能够快速更改编码。在此菜单中,您可以找到诸如“删除引号”、“删除空白行”以及“展开和重新包装文本”等选项

执行以下操作:

TextFX > TextFX Edit > Delete Blank Lines
TextFX > TextFX Edit > Delete Surplus Blank Lines

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 Text

Do the following:

TextFX > TextFX Edit > Delete Blank Lines
TextFX > TextFX Edit > Delete Surplus Blank Lines
感情旳空白 2024-10-03 08:42:52
  1. notepad++
  2. Ctrl-H
  3. 选择正则表达式
  4. 在查找内容中输入 ^[ \t]*$\r?\n ,将替换留空。这将匹配所有以空格开头并以回车符结尾的行(在本例中为 windows crlf)
  5. 单击“查找下一个”按钮,亲自查看它如何仅匹配空行。
  1. notepad++
  2. Ctrl-H
  3. Select Regular Expression
  4. Enter ^[ \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)
  5. Click the Find Next button to see for yourself how it matches only empty lines.
祁梦 2024-10-03 08:42:52
  1. ctrl + h(替换快捷键)。
  2. 查找内容区域中,输入 ^\R(对于精确的空行)或 ^\h*\R(对于带有空格的空行) , 仅有的)。
  3. 替换为区域留为
  4. 选中环绕选项。
  5. 选择正则表达式搜索模式。
  6. 单击全部替换按钮。

输入图片描述这里

  1. Press ctrl + h (Shortcut for replace).
  2. In the Find what zone, type ^\R ( for exact empty lines) or ^\h*\R ( for empty lines with blanks, only).
  3. Leave the Replace with zone empty.
  4. Check the Wrap around option.
  5. Select the Regular expression search mode.
  6. Click on the Replace All button.

enter image description here

倾其所爱 2024-10-03 08:42:52

您可以按照以下屏幕截图所示的方法进行操作:

  • 查找内容: ^\r\n
  • 替换为: 将其留空
  • 搜索模式: 正则表达式
  • 环绕:选择

在此处输入图像描述

注意:对于 *nix 文件只需通过 \n 查找

You can follow the technique as shown in the following screenshot:

  • Find what: ^\r\n
  • Replace with: keep this empty
  • Search Mode: Regular expression
  • Wrap around: selected

enter image description here

NOTE: for *nix files just find by \n

无人问我粥可暖 2024-10-03 08:42:52

这对我有用:

  1. ctrl + h(替换快捷键)
  2. 查找内容框中写入以下正则表达式之一。
    [\n\r]+$^[\n\r]+
  3. 中将替换为框留空
  4. 搜索模式< < /code>,选择Regex
  5. 单击全部替换

    完毕!

This worked for me:

  1. Press ctrl + h (Shortcut for replace)
  2. Write one of the following regex in find what box.
    [\n\r]+$ or ^[\n\r]+
  3. Leave Replace with box blank
  4. In Search Mode, select Regex
  5. Click on Replace All

    Done!

星星的轨迹 2024-10-03 08:42:52

1) Ctrl + H (或Search

1) Ctrl + H ( Or Search ???? 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 bracket

enter image description here
Refer https://www.rexegg.com/regex-quickstart.html for more on regex.

2024-10-03 08:42:52

在记事本++中按 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

寄居者 2024-10-03 08:42:52

您可以搜索以下正则表达式: ^(?:[\t ]*(?:\r?\n|\r))+ 并将其替换为空字段

You can search for the following regex: ^(?:[\t ]*(?:\r?\n|\r))+ and replace it with empty field

海拔太高太耀眼 2024-10-03 08:42:52

好吧,我不确定正则表达式或您的情况。

如何 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

叹梦 2024-10-03 08:42:52

Ctrl+H。

查找 - \r\r
替换为 - \r。

Ctrl+H.

find - \r\r
replace with - \r.

羅雙樹 2024-10-03 08:42:52

如果空行包含制表符或空格,这显然不起作用。许多网页(例如 http://www.guardian.co.uk/)包含这些白线,由于 HTML 编辑器错误而导致。

使用正则表达式删除空格,如下所示:

更改模式:[\t]+$
化为乌有。

其中 [\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:

change pattern: [\t ]+$
into nothing.

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.

爱的十字路口 2024-10-03 08:42:52

在此处输入图像描述

有时 \n\r 等不起作用,在这里弄清楚你的实际正则表达式应该是什么。

这个技巧的优点:如果你想一次替换多个文件,你必须需要这个方法。上面不行...

enter image description here

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...

千鲤 2024-10-03 08:42:52

此模式在 Notepad++ v8.1.1 中进行了测试,

它替换了每行文本之前和之后的所有空格/制表符/空白行。

它不应该扰乱文本中间的任何内容。

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
_____________________________________

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.

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
_____________________________________
放我走吧 2024-10-03 08:42:52
  1. 编辑>>空白操作>>修剪前导和尾随空格(删除空行中的黑色制表符和空格)
  2. Ctrl + H 获取替换窗口并替换模式:^\r\n< /code> 不包含任何内容(选择正则表达式)

注意:第 1 步将删除通过制表符和空格完成的代码意图

  1. Edit >> Blank Operations >> Trim Leading and Trailing Spaces (to remove black tabs and spaces in empty lines)
  2. Ctrl + H to get replace window and replace pattern: ^\r\n with nothing (select regular expression)

Note: step 1 will remove your code intendation done via tabs and blank spaces

嗳卜坏 2024-10-03 08:42:52

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

失退 2024-10-03 08:42:52

/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.

挽梦忆笙歌 2024-10-03 08:42:52

我没有看到合并后的答案,因此搜索 ^\s+$ 并替换为 {nothing}

^\s+$ means
  ^ start of line
  \s+ Matches minimum one whitespace character (spaces, tabs, line breaks)
  $ until end of line

I did not see the combined one as answer, so search for ^\s+$ and replace by {nothing}

^\s+$ means
  ^ start of line
  \s+ Matches minimum one whitespace character (spaces, tabs, line breaks)
  $ until end of line
﹉夏雨初晴づ 2024-10-03 08:42:52

上面的一些表达式和扩展表达式对我不起作用,但正则表达式“$\n$”对我有用。

A few of the above expressions and extended expressions did not work for me, but the regular expression "$\n$" did.

灯角 2024-10-03 08:42:52

从空行中删除空格的简单替代方法:

  1. TextFX>TextFX Edit>修剪尾随空格

这将删除所有尾随空格,包括空行中的尾随空格。
确保尾随空格不重要。

An easy alternative for removing white space from empty lines:

  1. TextFX>TextFX Edit> Trim Trailing Spaces

This will remove all trailing spaces, including trailing spaces in blank lines.
Make sure, no trailing spaces are significant.

自找没趣 2024-10-03 08:42:52

这对我有用:

SEARCH:^\r  
REPLACE:            (empty)

this work for me:

SEARCH:^\r  
REPLACE:            (empty)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文