2

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

3

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$
0

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. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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