Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 12 down vote accepted

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 ~.
share|improve this answer
if you change .*?~ to [^~]*~ then it should work without requiring / using PCRE. – barlop Feb 19 '13 at 17:46
@barlop: I took regular Find and Replace as Search Mode: Normal, not Find and Replace using regular expressions. That might have been a misunderstanding. In any case, if I remember correctly, versions prior to 6 did not support multi-line patterns. – Dennis Feb 19 '13 at 17:53

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.

share|improve this answer
Be careful with the regex's greedy behavior. If there are multiple ~ characters (or ie. multiple matches) this will match the first ^ all the way to the last ~. – heavyd Feb 19 '13 at 17:41
@heavyd: Thanks for noticing! :D – Oliver Salzburg Feb 19 '13 at 17:43
@heavyd <question>Are you sure?</question>. He has used *? that is not greedy it's lazy .*?~ will never match more than one ~. So it's ok. – barlop Feb 19 '13 at 23:12
@barlop: He commented shortly after I answered. It was a ninja-edit. – Oliver Salzburg Feb 19 '13 at 23:30

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

share|improve this answer
and for exclusively, then I suppose that requires PCRE, then do something (?<=^)[^~]*(?=~) I don't have n++ to test it, butif that fails try changing (?<=^) to (?<=\^) – barlop Feb 19 '13 at 17:54
For exclusively, just replace with ^~. – Dennis Feb 19 '13 at 17:55
@Dennis I mean if he wants to replace everything between the ^ and ~ but not including the ^ and ~ – barlop Feb 19 '13 at 17:56
Isn't that what you get if you replace \^[^~]*~ with ^~? – Dennis Feb 19 '13 at 17:57
@Dennis oh I see what you mean, good point. – barlop Feb 19 '13 at 17:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.