Wildcards in Notepad++ – efficient search and replace

Daniel Saffer

24/05/2019

Notepad++ is a free text editor. It supports various programming languages for easy source code editing. Similar to development environments, it uses typographical features. This means that the text is formatted in its appearance. The formatting depends on the syntax and structure of the programming language. Notepad++ can use regular expressions (so-called RegExp) in the "Find and Replace" function. One use case for regular expressions is wildcards, which we'll discuss shortly.

Overview

This article has become a bit longer due to the examples. Use the links to access the individual points.

Search and replace

The “Find and Replace” function in Notepad++ can be accessed in two ways:

  1. Possibility:
    Under "Find" in the menu bar, select the "Replace..." list entry. The desired window will then open.
  2. Possibility:
    The simpler option is to simultaneously CTRL+H The desired window will then open.

Wildcards

Wildcards are placeholders for other characters. They can be used in the "Find and Replace" function in Notepad++. The most important wildcards are listed below and their use is described. The table shows the notation in Notepad++. A "." is often required before a wildcard.

Wildcard Description
.? or . A question mark searches for exactly one character.
.* An asterisk searches for any number of characters (including zero).
[] Only characters enclosed in square brackets are searched for. Using square brackets alone does not constitute a valid expression.

Sign:
A search for "A[bc]d" therefore results in "Abd" and "Acd." You can also specify a range. For example, a search for B[ac]A results in BaA, BbA, and BcA.

Pay:
Searching for "[0-8]" matches all numbers from 0 to 8 excluding 9. It is also possible to search for individual numbers [2].

Any Latin letters or any numbers:
Searching for "[A-Za-z0-9]" matches all Latin letters and numbers.

Exclude characters:
The "^" character can be used to exclude certain characters. "[^1]" searches for all characters and numbers excluding the "1."

Quantifiers

The use of quantifiers is optional. They extend wildcards and allow you to find repetitions in strings. The syntax is:
<Wildcard><Quantor>

quantifier Description
? If you add a question mark to a wildcard, this expression does not have to appear, but it can.
+ The plus sign means that the preceding expression must occur at least once, but can be repeated any number of times.
* The preceding expression may occur any number of times. Unlike the plus sign, the expression may also not occur once.
{n} The preceding expression must occur exactly n times.
{n,} The preceding expression must occur at least n times.
{n,m} The preceding expression must occur between n and m times.
{0,m} The preceding expression may occur a maximum of m times.

For example, if you search for [from]{2}_ you get: "aa," "bb," "ab," and "ba." Wildcards and quantifiers can be combined in any way.

Metacharacters

Metacharacters have a special meaning for string processing in a specific context. When using regular expressions, such as Notepad++'s "Find and Replace" function, the following metacharacters have a special meaning:

Metacharacters Description
^ This metacharacter represents the beginning of a line or string
$ A dollar sign represents the end of a line or string
? + * { } Used with wildcards and quantifiers
\ Convert a metacharacter into a “normal” character so that it can be searched for.
( ) Groupings to enable complex search and replace operations. If you want to find a text of any length between two characters, e.g., "<" and ">", and then remove the two characters, you can use parentheses. These are also called tagged expressions. Multiple tagged expressions can be used within a search. In the replace section, the tags are used \1_, \2_, etc. The first bracket can then be accessed, for example, with the tag \1_ be called.

The search expression could then look like this: <(.*)>_. This means that any number of characters between the greater than and less than sign are searched for. The replace part then writes \1_. The search will then be replaced by the contents of the brackets, i.e. any characters.

| Alternatives or logical “OR”
\n New line "line feed"
\r New line “carriage return”
\t tab
\d Any digit
\w Any letter
\s One space (whitespace)
\b Empty string at the beginning or end of a word
\B Empty string that does not form the beginning or end of a word

Example: Get payload from a data stream

Notepad++'s search function is very efficient. It's perfect for capturing log files from a serial data transfer and searching for specific packets. Message packets often consist of a start byte, a command, the payload, a checksum, and a stop byte.

Start byte command Package counter Payload Checksum Stop byte
0x01 0x12 1 byte 3 bytes 2 bytes 0x04

In this example, we want to retrieve the payload from a serial data stream. Each payload should be output on a new line to make the data easier to read. The initial recording looks like this:

The entire recording is displayed on only one line, which is very unreadable. However, we know that each packet ends with the stop byte 0x04. We can therefore replace the character 0x04 with 0x04\n. \n is a line feed, or a newline. Notepad++ accepts these special characters in advanced search mode. The replacement looks like this:

Each message packet now appears on a new line.

In the next step, we remove the start byte, the command, and the packet counter from the payload. The start byte and the command do not vary in this example; the packet counter is incremented on each line. Therefore, the search must be 01 12 .?.?_.

The message beginning has now been successfully removed:

Now only the end of the message is removed. This consists of a 2-byte checksum and the stop byte. The search is therefore .?.? .?.? 04_After this step, only the payload remains and the desired result has been achieved.

And the result:

Example: Text within a <div>-Replace tags

This example demonstrates how to easily change the text of HTML buttons. Several buttons with the ID "test" are embedded on a website. The texts are different, but should be changed to "learn more." The code looks like this:

Even though lines 2 and 3 look the same at first glance, you can see that there's an extra space in line 3 and the text between the divs is longer. Therefore, the search expression should look like this:

The result:

 

Example: Remove subpages from URLs

In this example, the subpages of URLs are removed. The existing list looks like this:

medtech-ingenieur.de/index.php medtech-ingenieur.de/?p=3133&preview=true medtech-ingenieur.de/blog/ medtech-ingenieur.de/dependability-in-der-medizintechnik/

Each subpage can be found using the command "de/.*." This is then replaced with "de/" or "de." Make sure the "finds \r and \n" checkbox is unchecked.

The result is then:

medtech-ingenieur.de medtech-ingenieur.de medtech-ingenieur.de medtech-ingenieur.de

Example: Parsing values from parentheses

When debugging, it's sometimes necessary to examine long arrays more closely. If you copy the values directly from the development environment, the row numbers and other information are often transferred along with them. The copy might look like this for a ring buffer (copied from Android Studio):

In this case, only the hexadecimal values are of interest to the developer. He also wants to see which messages are stored in this ring buffer. With just one command, all values can be displayed in one line. The use of parentheses is also called a tagged expression or grouping. Using the \1 tag, the contents of the first parentheses in the search can be accessed. The query looks like this:

Here you can see the result:

The developer knows that every message packet ends with 0xFD. In the next step, we can therefore insert a newline (\n) after each 0xFD. This will show all the message packets in the ring buffer.

Example: Formatting the date consistently

A list with multiple dates is formatted differently. Using Notepad++'s "Find and Replace" function, all dates should be converted to the format "##-##-####." The list looks like this:
In the first step, we replace all characters between the lines with the "-" character. Tagged expressions can be used multiple times within the search. The individual brackets can then be accessed using the tags \1, \2, etc. The number reflects the order of the brackets.

The result of the first run looks like this:

Unfortunately, not all data yet has the desired format "##-##-####." Therefore, a second pass with the following search is required:

You will then receive the desired format.


If you have any questions or would like more examples, please leave a comment. We'll be happy to help.

Best regards
Daniel Saffer


Written by Daniel Saffer

Daniel Saffer is Chief Technical Officer (CTO) of MEDtech Ingenieur GmbH. In this role, he is responsible for the company's technical strategy and supports customer projects in medical technology. His focus is on the further development of safety-critical software solutions, regulatory requirements, and innovative technologies for the industry.


More articles

  • 09/09/2025
  • General, Software

In previous blog posts, I have introduced two essential components of a simple and universally applicable software architecture: events with dispatchers, listeners, and data pools. These already allow for many simple use cases ...

Read more
  • 12/11/2024
  • General, Software, Testing, Tools

In safety-critical software projects, software quality is paramount. Especially for Class C software, which must be certified according to strict standards such as IEC 62304 (medical technology), it is essential that ...

Read more
  • 08/08/2024
  • General, Electrical Stimulation, Software, Testing

Nowadays, apps in the healthcare sector are very important. Apps that can read and process data from medical sensors are particularly useful. Flutter is an open-source framework from Google that is excellent for ...

Read more
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Strictly Necessary Cookies

Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.