fork download
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. var s = "A ---\r\nsome text of many lines\r\nB ---\r\n\r\nother text with some lines\r\nand text and\r\ntext \r\n\r\nC --- \r\nmore text and tokens and text\r\n\r\nQQ--- \r\n\r\nmore text more text\r\n\r\nHH---\r\nJJ---\r\n";
  9. var pat = @"^(?<token>[a-zA-Z].--.*)(?<content>(?:\r?\n(?![a-zA-Z].---).*)*)";
  10. var result = Regex.Matches(s, pat, RegexOptions.Multiline)
  11. .Cast<Match>()
  12. .Select(m => new[] {m.Groups["token"].Value.Trim(), m.Groups["content"].Value.Trim()});
  13. foreach (var pair in result)
  14. Console.WriteLine($"--- New match ---\nToken: {pair[0]}\nContent: {pair[1]}");
  15. }
  16.  
  17. }
  18.  
  19.  
Success #stdin #stdout 0.04s 134208KB
stdin
Standard input is empty
stdout
--- New match ---
Token: A ---
Content: some text of many lines
--- New match ---
Token: B ---
Content: other text with some lines
and text and
text
--- New match ---
Token: C ---
Content: more text and tokens and text
--- New match ---
Token: QQ---
Content: more text more text
--- New match ---
Token: HH---
Content: 
--- New match ---
Token: JJ---
Content: