How do I delete lines without "." in Notepad++?

How to delete lines without .?

  • Menu "Search" > "Replace" (or Ctrl + H)

  • Set "Find what" to ^[^\.]*\r\n

    • You can replace \r\n with different EOL (End of Line) regular expressions depending on the EOLs in your file (see "I have a different EOL in my file, what can I do?" and "I don't care what EOLs my file uses, what can I do?" below).
  • Clear "Replace with"

  • Enable "Regular expression"

  • Click "Replace All"

    Image

Notes:

  • The above assumes that the last line in the file has a trailing EOL.

  • The above also assumes you are editing a text file with Windows EOLs, \r\n.

Before:

abc.xyz
abcdef
abc 123.xyz
abc 123def

After:

abc.xyz
abc 123.xyz

I have a different EOL in my file, what can I do?

  • The Windows EOL is \r\n.

  • If you are using files with a different EOL you can convert them to Windows EOLs using Menu "Edit" > "EOL Conversion".

  • If you aren't working with Windows EOLs, and you don't wish to convert them, use the following instead:

    • Use \n instead of \r\n for Unix/OS X EOLs

    • Use \r instead of \r\n for Mac OS (up to version 9) EOLs


I don't know or care what EOLs my file uses, what can I do?

  • You can use \R or (?:\r\n?|\n) or (?:\r?\n?) instead of \r\n. This gets around any issue with the EOLs actually used in the file.

  • You can also use (?:\r?\n?|$). This expression will work if there is no EOL in the last line of the file.


Further reading

  • Notepad++: A guide to using regular expressions and extended search mode
  • Regular Expressions Tutorial
  • RegExr: Learn, Build, & Test RegEx
  • regex101: Online regex tester and debugger

The accepted answer is correct, but you won't always have regex at ready. So I present a simpler solution.

  1. Ctrl+F – click on tab Mark
  2. Set "Find what" to .
  3. Check option "Bookmark line" (courtesy of Wrass)
  4. Search mode = Normal
  5. Click Mark All -> You should see a blue circle next to the bookmarked line numbers.
  6. Then navigate to menu Search -> Bookmark -> Remove Unmarked Lines.