Prerequisite: Using Notepad++ regular Find and Replace commands.

Notepad++ Secrets: Extended Find and Replace Characters

© 2012, Martin Rinehart

Programmer's editor Notepad++ has one tabbed dialog that starts with a Find tab and continues (mostly adds to it) with a Replace tab. They each feature an inconspicuous box, bottom-left, labelled "Search Mode":
The Find and Replace dialogs Search Mode box.

This short page will get you started on the wonders this little box hides.

Normal Search Mode

This is the default, where you got started. We assume you're comfortable here.

Extended Search Mode

The "Extended" mode adds various common "Escaped" characters to the normal set. An escaped character is one preceded by a backslash which gives it a special meaning. These are common in programming languages and in more powerful editors. Three that will be used here are:

Different characters are used to signal "EOL" (end-of-line) in different operating systems. The two most common today are \n (called "newline"), used in Unix-derived operating systems, such as Linux and Mac OS/X, and \r\n (return/newline is the old typewiter-based combination of carriage return and linefeed) used in Windows text files. To see your characters, try View/Show Symbol/Show End of Line. Ours looks like this:

This HTML file, showing end-of-line characters.

As you can see, unlike displaying just tabs, showing EOL characters is quite disruptive. (And, unfortunately we think, it turns off the tab display. We turned ours back to showing tabs, right after we took this screenshot.)

Now let's say we've decided to save a little vertical real estate in our files by starting that image tag on the same line with the <div> tag. We'll use the extended search mode to do a find that crosses from one line to the next, this way:

Finding characters across two lines.

Read that "Find what:" specification slowly: a ">", then an EOL ("\r\n"), a tab ("\t") and last "<img". Once that string is found this will replace it with just a space (no EOL) separating ">" and "<img". (Picture your file on disk, where it is one continuous stream of characters.)

That will come out, after we find/replace, like this:

This HTML file, not showing end-of-line characters.

Your job is to make a similar change in one of your own files, but make it manually (converting two lines to one, preferably in several places). Then use the extended characters to find/replace your file back to the way it was. You'll need to be very comfortable here to go on to the last step.

Regular Expression Search Mode

Regular expressions are very powerful and probably more cryptic than anything else in the world of programming. But they can solve problems that would otherwise require a full computer program. If you're ready, try the next page on the menu above.


Feedback: MartinRinehart at gmail dot com.

# # #