作者:刘德华 | 来源:互联网 | 2023-05-30 17:31
UsingNotepad++,howdoIremovealllinesstartingwith#or;?使用Notepad++,如何删除以#或;开头的所有行?
Using Notepad++, how do I remove all lines starting with # or ;?
使用Notepad++,如何删除以#或;开头的所有行?
5 个解决方案
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 ->显示符号->显示行尾。