Notepad++ - Replace with Regular Expression

> Integrated development environment (ide) > NotePad++

1 - About

Replace with regular expression in Notepad++.

Notepad++ uses the Boost Library (C++). For the whole regex pattern format, you may have to refer to it.

3 - Tutorial

3.1 - The Input text

Input with windows end of line (ie \r\n)

Hello          Print Hello
Youhou         Print Youhou

You can see the end of line when checking the “View all characters” options (View > Show Symbol > Show all characters or the reverse P icon)


3.2 - The Search Mode options


  • regular expression means that you input is a regular expression
  • . matches newline if the checkbox is checked means that the search will not occurs for each line but for the whole document when the dot is used.

3.3 - Regular Expression


which means:

  • takes all alphabetical characters (\w) until you found something that is not a alphabetical character.
  • takes all space until you found something that is not a space (the \s class means any whitespace character)
  • takes all characters . until you found the end of line \r\n or nothing {0,1} (ie the end of file)

Don't check the check box ( . matches newline )

3.4 - Replace

Replace with

| \1 | \3 |\4


  • \1 correspond to the match of the first pair of parenthesis,
  • \2 to the second and so on.

The fully qualified expression for substitution is


and must be used when:

  • the number of group is greater than 9
  • you want a number that follow the substitution

3.5 - Output

Output after hitting the replace button:

| Hello | Print Hello |
| Youhou | Print Youhou |

4 - Snippets

4.1 - Take all letters until a separator character is reached

This is achieve with the negation character ''^'' of a class

Example with the - minus. Take all characters until a minus is found:

  • Find what:
  • Replace with:

Example of input:


gives this output:


4.2 - Replace a character with new line

4.3 - Suppress blank line

5 - Documentation / Reference