fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. var text =
  9. @"WORD
  10. [asdf] ---
  11. 123/\*&
  12. WORD
  13. [asdf] ---
  14. 123/\*&
  15. ENDWORD
  16. [asdf] ---
  17. 123/\*&";
  18.  
  19. var pattern = @"[ \t]WORD\b.*(?:\r?\n(?!.*[ \t](?:END)?WORD\b).*)*\r?\n[ \t]+ENDWORD\b";
  20.  
  21. Regex rgx = new Regex(pattern);
  22. foreach (Match match in rgx.Matches(text))
  23. {
  24. Console.WriteLine(match.Value);
  25. }
  26. }
  27. }
Success #stdin #stdout 0.09s 21332KB
stdin
Standard input is empty
stdout
 WORD
    [asdf] ---
    123/\*&
    ENDWORD