Notepad++ Regex – Find and Replace Text Between ^ and ~

notepadregex

I have a large text file where I want to remove all text between the ^ symbol and the ~ symbol. This needs to work across lines as well.

I tried doing a regular Find and Replace using ^*~ in the Find box and nothing in the Replace box but it found 0 results.

Best Answer

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 ~.
Related Question