热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

删除以#或开头的所有行;在记事本++-Deletealllinesstartingwith#or;inNotepad++

UsingNotepad++,howdoIremovealllinesstartingwith#or;?使用Notepad++,如何删除以#或;开头的所有行?

Using Notepad++, how do I remove all lines starting with # or ;?

使用Notepad++,如何删除以#或;开头的所有行?

5 个解决方案

#1


91  

Find:

发现:

^[#;].*

Replace with nothing. The ^ indicates the start of a line, the [#;] is a character class to match either # or ;, and .* matches anything else in the line.

取代一无所有。^表示一行的开始,[#;]是一个字符类比赛#或,,。*匹配任何其他的线。

In versions of Notepad++ before 6.0, you won't be able to actually remove the lines due to a limitation in its regex engine; the replacement results in blank lines for each line matched. In other words, this:

在6.0之前的Notepad++版本中,由于regex引擎的限制,您无法实际删除这些行;替换将导致每一行匹配的空行。换句话说,这个:

# foo
; bar
statement;

Will turn into:

会变成:



statement;

However, the replacement will work in Notepad++ 6.0 if you add \r, \n or \r\n to the end of the pattern, depending on which line ending your file is using, resulting in:

但是,如果您将\r、\n或\r\n添加到模式的末尾,则替换将在Notepad++ 6.0中工作,这取决于您的文件使用的是哪一行,结果是:

statement;

#2


6  

As others have noted, in Notepad++ 6.0 and later, it is possible to use the "Replace" feature to delete all lines that begin with ";" or "#".

正如其他人所注意到的,在Notepad++ 6.0和以后的版本中,可以使用“替换”功能来删除以“;”或“#”开头的所有行。

Tao provides a regular expression that serves as a starting point, but it does not account for white-space that may exist before the ";" or "#" character on a given line. For example, lines that begin with ";" or "#" but are "tabbed-in" will not be deleted when using Tao's regular expression, ^(#|;).*\r\n.

Tao提供一个正则表达式作为起点,但它不表示给定行上的“;”或“#”字符之前可能存在的空白。例如,行,开始“;”或“#”,但“以标签的形式显示在”不会被删除使用道的正则表达式时,^(# |;)。* \ r \ n。

Tao's regular expression does not account for the caveat mentioned in BoltClock's answer, either: variances in newline characters across systems.

Tao的正则表达式不能解释BoltClock回答中提到的警告:换行字符跨系统的方差。

An improvement is to use ^(\s)*(#|;).*(\r\n|\r|\n)?, which accounts for leading white-space and the newline character variances. Also, the trailing ? handles cases in which the last line of the file begins with # or ;, but does not end with a newline.

一个改进是使用^(\ s)*(# |;)。*(| | \ r \ n \ r \ n)?它解释了前导空格和换行字符方差。此外,拖尾?处理文件的最后一行以#或;但不以换行结束的情况。

For the curious, it is possible discern which type of newline character is used in a given document (and more than one type may be used): View -> Show Symbol -> Show End of Line.

对于好奇的人来说,可以辨别在给定的文档中使用了哪种换行字符(可以使用多种类型):View ->显示符号->显示行尾。

#3


5  

Its possible, but not directly.

这是可能的,但不是直接的。

In short, go to the search, use your regex, check "mark line" and click "Find all". It results in bookmarks for all those lines.

简而言之,进入搜索,使用您的regex,检查“mark line”并单击“查找所有”。它为所有这些行生成书签。

In the search menu there is a point "delete bookmarked lines" voila.

在搜索菜单中有一个点“删除书签行”。

I found the answer here (the correct answer is the second one, not the accepted!): How to delete specific lines on Notepad++?

我在这里找到了答案(正确的答案是第二个,而不是被接受的!):如何删除Notepad++上的特定行?

#4


2  

Maybe you should try

也许你应该试试

^[#;].*$

^ matches the beggining, $ the end.

^匹配发出召唤,美元。

#5


-1  

In Notepad++, you can use the Mark tab in the Find dialogue to Bookmark all lines matching your query which can be regex or normal (wildcard).

在Notepad++中,您可以在Find对话中使用标记选项卡来标记所有与您的查询匹配的行,这些行可以是regex或normal(通配符)。

Then use Search > Bookmark > Remove Bookmarked Lines.

然后使用Search > Bookmark >删除书签行。


推荐阅读
author-avatar
刘德华
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有