Find and Replace text between ^ and ~ in Notepad++

This is not possible with a regular Find and Replace. If you use Notepad++ 6, you can take advantage of the new regex engine that supports PCRE (source).

Press Ctrl + H to open the Find and Replace dialog and perform the following action:

Find what:          \^.*?~
Replace with:       
Wrap around:        checked
Regular expression: selected
. matches newline:  checked

Now press Alt + A to replace all occurrences.

The regular expression in Find what is composed as follows:

  • \^ is a literal ^.
  • .*? is the least amount of characters that allows the regular expression to match.
  • ~ is a literal ~.

You're gonna want to search for \^.*?~ and make sure . matches newline is enabled:

enter image description here

This is because ^ has a special meaning, it matches the beginning of a line. Thus, we need to escape it with a backslash \^.

Writing ^* would match "any number of start-of-line in a row". .* matches "any character", but by default it doesn't match newlines.


Try using this regex in the find section \^[^~]*~ to replace everything between ^ and ~ inclusively.