[regex] Delete all lines starting with # or ; in Notepad++

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

This question is related to regex notepad++

The answer is


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

Then use Search > Bookmark > Remove Bookmarked Lines.


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.

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++?


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.


Maybe you should try

^[#;].*$

^ matches the beggining, $ the end.