| Finally, I use ^[^#].+\n to delete all lines that don’t start with a hash mark.
That expression seems to have three possible issues.
It will match and delete \n\n# Some stuff you wanted to keep as [^#] matches \n in the data. It won’t match \n#\n~ in the data though it should be removing a line that only has a # at the beginning. While you use \n in your expressions can you guarantee that there is never a \rn or \r\n pair in your data?A safer expression is ^[^#\r\n].*\R.
Notepad++ regexp is a little different than some other regexp engines in that in Notepad++ [^#] will also match end of line characters such as \n or \r Also, the [^#] only matches one character. If you have a two-character CRLF in your data it will match just the CR (\r) and the next character in the data stream is a LF (\n).