I kinda know how to keep delete all line start with # with the code
^[#].*
But I wonder how to do the reverse? keep all the line start with # and delete the rest.
In order to do that, you just use negated character class in your regex:
^[^#].+
[^#]
means match everything except #
, so please see picture below for better understanding:
Then just replace all, this will empty lines. So then you need to match new line characters only with ^\r\n
(depending on operation system, it could be also ^\n
) and again replace it with empty string: