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).
- You can replace
Clear "Replace with"
Enable "Regular expression"
Click "Replace All"
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 EOLsUse
\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.
- Ctrl+F – click on tab Mark
- Set "Find what" to
.
- Check option "Bookmark line" (courtesy of Wrass)
- Search mode = Normal
- Click Mark All -> You should see a blue circle next to the bookmarked line numbers.
- Then navigate to menu Search -> Bookmark -> Remove Unmarked Lines.