在记事本++中的多个文件中删除带有特定单词的行 [英] Deleting lines with specific words in multiple files in Notepad++

查看:199
本文介绍了在记事本++中的多个文件中删除带有特定单词的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从使用Notepad ++处理的许多文件中删除特定行。

I'm trying to removing a specific line from many files I'm working on with Notepad++.

在搜索时,我发现记事本++删除目录中多个文件中带有特定单词的行,但以某种方式提供了正则表达式( ^。*(?: YOURSTRINGHERE)。*答案中的\r\n $ )对我不起作用(屏幕截图: https://cdn.discordapp.com/attachments/311547963883388938/407737068475908096/unknown.png )。

Upon searching, I found Notepad++ Remove line with specific word in multiple files within a directory but somehow the regex provided (^.*(?:YOURSTRINGHERE).*\r\n$) from the answers doesn't work for me (screenshot: https://cdn.discordapp.com/attachments/311547963883388938/407737068475908096/unknown.png).

I请阅读某些其他正则表达式在较新/较旧的Notepad ++版本中不起作用的问题/答案。我使用的是Notepad ++ 5.xx,然后将其更新为最新的7.5.4,但均不能使用上述问题中提供的正则表达式。

I read on some other questions/answers that certain regex doesn't work in newer/older Notepad++ versions. I was using Notepad++ 5.x.x then updated to the latest 7.5.4, but neither worked with the regex provided in the question above.

目前,我可以解决此问题。通过不使用任何内容替换该行两次(因为我只需要从这些文件中删除2个变体),但是在文件末尾留空行。因此,我必须进一步采取措施以删除该空行。

At the moment I can work around it by replacing that line with nothing, twice (because there are only 2 variants that I need to remove from those files) but that leaves an empty line at the end of the files. So I have to do another step further to remove that empty line.

我希望有人可以提供帮助,使我可以删除该行并且不留空行/

I'm hoping someone can offer helps that allow me to remove that line and leave no empty line/space behind.

推荐答案

您尝试使用的正则表达式仅与您的行匹配,如果它后面跟着一个空行和Windows使用换行符(CR LF)。这是由于 \r\n $ 与换行符相匹配,后跟行尾。

The regex you attempt to use will only match your line, if it is followed by an empty line and Windows linebreaks (CR LF) are used. This is due to \r\n$ which matches a linebreak sequence followed by the end of the line.

相反,您可能想使用

^.*(?:YOURSTRINGHERE).*\R?

要匹配包含字符串的行以及以下可选的换行符序列,以删除该行而不是清空出来。如果您的单词包含在文件的最后一行,则将在结尾加上换行符。您可以使用

To match the line containing your string and optionally a following line break sequence to remove the line instead of emptying it out. This will leave you with a trailing newline, if your word is contained in the last line of a file. You can use

(\R)?.*(?:YOURSTRINGHERE).*(?(1)|\R)

为避免这种情况。它使用条件匹配上一个换行符,或者匹配不存在的换行符。

To avoid this. It uses a conditional to either match the previous linebreak, or the following if there is none.

这篇关于在记事本++中的多个文件中删除带有特定单词的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆