Notepad++ Extended Search

Do you want to know more about Notepad++ Extended Search?

Search and replace is familiar with almost anybody who have touched a computer. It's easy and obvious to replace a string with another. But you can do much more complex operations than that, thanks to advanced find-and-replace feature added to modern text editors like Notepad++.

This article will show you how to use Notepad++ Extended Search and a few common examples. For example, you can replace strings that contains special characters such as NULL (empty) or Carriage Return.

What can I do with Extended Search in Notepad++?

According to official Notepad++ User Manual, Extended Mode allows you to use escape string (backlash) followed by a character to find and replace special characters.

In other words, whenever you enable Extended Mode, Notepad++ will look for escape codes in the table below and translate it to the special, non-literal value in "Translated Character" column.

Escape code Translated Character
\n Line Feed character LF
\r Carriage Return character CR
\t TAB character
\0 NUL character
\\ backslash character

Within Unicode-encoded files, you can even find a character using its Unicode code-point with limited support for only U+00xx (xx ranging from 00 to ff).

A character within this range can be easily represented in decimal syntax d*** where *** is the decimal code of the Unicode character (from 000 (U+0000) to 255 (U+00FF)).

What I cannot do with Extended Search?

  • Use regular expressions
  • Replace Unicode emojis
  • Searching individual bytes of an UTF-8 or UCS-2 encoded character

Search-and-Replace newlines in Notepad++

On Windows, a new line is marked using a Carriage Return (CR) followed by a Line Feed (LF) control characters.

On the other hand, Linux marks a newline using only a LF.

You can look at the lower right corner of Notepad++ window to know how your files was encoded. In this example, we're operating on files encoded in Unix style (LF newlines).

image-20210505161752535

In order to put everything in one line, you would have to replace all newlines with a blank character. First, open up Search and Replace by pressing Ctrl + H.

Make sure you selected Extended Mode in Search Mode and checked Match case.

image-20210505161958666

Next, input \n into Find what box and make sure Replace with box is clear. Now click Replace All and everything is on one line only.

image-20210505162124634

Search-and-Replace tabs in Notepad++

Suppose we have the code snippets below and want to replace tabs with spaces.

for y in $objects
do
    # extract the size in bytes
    size=$((`echo $y | cut -f 5 -d ' '`/1024))
    # extract the compressed size in bytes
    compressedSize=$((`echo $y | cut -f 6 -d ' '`/1024))
    # extract the SHA
    sha=`echo $y | cut -f 1 -d ' '`
    # find the objects location in the repository tree
    other=`git rev-list --all --objects | grep $sha`
    #lineBreak=`echo -e "\n"`
    output="${output}\n${size},${compressedSize},${other}"
done

Now that we know \t represents a TAB character, we follow the same process as in the example above, you need to open up Search and Replace first by pressing Ctrl + H.

Make sure Extended Mode and Match case are selected.

image-20210505162649519

In order to replace every tab with four spaces, input \t into Find what and four spaces into Replace with. Now click Replace All and watch the results.

Search-and-Replace special Unicode characters in Notepad++

Suppose we have a few "dagger" characters in the file content which we want to get rid of. Since this "dagger" character sits in the range that Notepad++ Extended Mode supported, we can leverage this to quickly search and replace it.

image-20210505163541521

First, open up Search and Replace using Ctrl+H like you would normally do. You need to replace \u2020, which is the Unicode code-point of it with nothing. Please look at the image below and see what I mean.

image-20210505163435832

Press Replace All and voilà, all "dagger" characters removed.

image-20210505163552410

Click to rate this post!
[Total: 27 Average: 5]

Leave a Comment