Delete all lines starting with # or ; in Notepad++

前端 未结 5 1128
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 09:53

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

5条回答
  •  爱一瞬间的悲伤
    2020-12-07 10:29

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

    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's regular expression does not account for the caveat mentioned in BoltClock's answer, either: variances in newline characters across systems.

    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.

    For the curious, it is possible to 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.

提交回复
热议问题