Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
Home

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 Superuser.com could use some reputation points :)

Let me know if you need further info.

Thanks,

Richie

share|improve this question
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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.