The latest version : 5.5.1

 

 

Notepad++ newline search and replace FAQ   3/10/06, tested on v3.9 beta

Author : Peter Shute


Searching for, and replacing, newlines in Notepad++ results in a lot of help requests. This is because there are 2 search and replace commands, each with 2 modes (regular expressions or no regular expression) and some bugs inherited from the Scintilla Project that Notepad++ is based on. Some things that work in search strings don't work in replace strings, and vice versa. Hopefully this FAQ will cover all the possible cases so that everyone's questions will be answered.

1. The Search field:

1.1 Simple search (Ctrl+H) without regexp

You can turn on View/Show End of Line or view/Show All, and select the now visible newline characters. Then when you start the command some characters matching the newline character will be pasted into the search field. Matches will be replaced by the replace string, unlike in regex mode.

Note 1: If you select them with the mouse, start just before them and drag to the start of the next line. Dragging to the end of the line won't work.
Note 2: You can't copy and paste them into the field yourself.

1.2 Simple search (Ctrl+H) with Regexp

The $ symbol will match newlines, but they won't be replaced by the replace string. They only help locate the position of it - you can only use them at the end of the search string, because this command only searches within lines in this mode.

1.3 Advanced search (Ctrl+R) without regexp

Ctrl+M will insert something that matches newlines. They will be replaced by the replace string.

1.4 Advanced search (Ctrl+R) with Regexp

Can't be done.

2. The Replace field:
 
2.1 Simple search (Ctrl+H) without regexp

Can't be done.

2.2 Simple search (Ctrl+H) with Regexp

The $ symbol will insert a newline.

2.3 Advanced search (Ctrl+R) without regexp

Ctrl+M will replace the search text with a newline.

2.4 Advanced search (Ctrl+R) with Regexp

Oddly, Ctrl+M will replace the search text with a newline, but $ just replaces it with a $.