using System;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
var text =
@"WORD
[asdf] ---
123/\*&
WORD
[asdf] ---
123/\*&
ENDWORD
[asdf] ---
123/\*&";
var pattern = @"[ \t]WORD\b.*(?:\r?\n(?!.*[ \t](?:END)?WORD\b).*)*\r?\n[ \t]+ENDWORD\b";
Regex rgx = new Regex(pattern);
foreach (Match match in rgx.Matches(text))
{
Console.WriteLine(match.Value);
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGV4dC5SZWd1bGFyRXhwcmVzc2lvbnM7CgpwdWJsaWMgY2xhc3MgVGVzdAp7CglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CgkJdmFyIHRleHQgPQogICAgQCJXT1JEIAogICAgW2FzZGZdIC0tLQogICAgMTIzL1wqJgogICAgV09SRAogICAgW2FzZGZdIC0tLQogICAgMTIzL1wqJgogICAgRU5EV09SRAogICAgW2FzZGZdIC0tLQogICAgMTIzL1wqJiI7CgogICAgICAgIHZhciBwYXR0ZXJuID0gQCJbIFx0XVdPUkRcYi4qKD86XHI/XG4oPyEuKlsgXHRdKD86RU5EKT9XT1JEXGIpLiopKlxyP1xuWyBcdF0rRU5EV09SRFxiIjsKCiAgICAgICAgUmVnZXggcmd4ID0gbmV3IFJlZ2V4KHBhdHRlcm4pOwogICAgICAgIGZvcmVhY2ggKE1hdGNoIG1hdGNoIGluIHJneC5NYXRjaGVzKHRleHQpKQogICAgICAgIHsKICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUobWF0Y2guVmFsdWUpOwogICAgICAgIH0KCX0KfQ==