Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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 need to know the syntax for a regular expression (notepad++) to help me find/replace every instance of following string in a text document

the string is as follows

Where do you want to go next?
some text
some text
some text

Now, the 'some text' could be a single line or multiple lines of text. Some of the time, the 'Where do you want to go next?' string will only have one line of text between it and Home.

The very last item in this list will always be the word Home, with a capitol H.

I want to remove every instance of this block of text (which appears literally hundreds of times in this document) from Where do you want to go next?, any 'some text' lines and the word Home.

Where i was running into issues was the fact that 'some text' was variable and started on a new line. I have to admit I am not that great at regular expressions, so I figure someone on could use some reputation points :)

Let me know if you need further info.



share|improve this question
up vote 3 down vote accepted

Newer version of Notepad++ (>6.1.x I think) now supports multi line matching (I am now using 6.1.5)

In the Find/Replace dialog, next to the "Regular Expression" radio button, there is a checkbox called ". matches newline" which means multi line matching.

Tick that checkbox then use this regex:

^Where do you want to go next\?.*?^Home$
share|improve this answer
Works for me! thanks! – Richie086 Aug 15 '12 at 7:05

This regex worked for me:

^Where do you want to go next?\r\n(.*\r\n)*?Home$

Windows uses \r\n for new lines. Unix-based systems just use \n.

This distinction just occurred to me now, so thank you for teaching me something new. :-)

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .