Tuesday, June 24, 2014

Regular Expression to Find or Select All Characters Between Two Strings in Notepad++

Regex to search and select text or characters between two given text or character strings given String1 and String2 in Notepad++. Use recent versions of Notepad++. Older versions do not parse regular expressions for multiple lines correctly.  The following regex should also work in other software that use regular expressions.

One Line (Greedy Version)

Will select all characters between first and last instance of strings :

String1.*String2

One Line (Non-greedy Version) 

Will select all characters between first and next instance of strings :

String1.*?String2

Multiple Lines (Greedy Version)

String1(?s)(.*)String2

Multiple Lines (Alternative Regex)

String1[\s\S]*String2

Multiline Search Plugins

Two Notepad++ plugins that may help with multiline find and replace search are TextFX and ToolBucket:

TextFX → Quick → Find/Replace

ToolBucket → Multiline find and replace