fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var s = "Foo: Some Text Bar: Some Other Text Foo-Bar: Even More Text";
  10. var res = Regex.Split(s, @"(?<!^)\s+(?=\b(?:Bar|Foo(?:-?Bar)?):)");
  11. Console.WriteLine(string.Join("\n", res));
  12. Console.WriteLine("--- Another idea ---");
  13. var matches = Regex.Matches(s, @"\w+(?:-\w+)*:.*?(?=\s*(?:\w+(?:-\w+)*:|$))", RegexOptions.Singleline)
  14. .Cast<Match>()
  15. .Select(x => x.Value)
  16. .ToList();
  17. Console.WriteLine(string.Join("\n", matches));
  18. }
  19. }
Success #stdin #stdout 0.06s 22276KB
stdin
Standard input is empty
stdout
Foo: Some Text
Bar: Some Other Text
Foo-Bar: Even More Text
--- Another idea ---
Foo: Some Text
Bar: Some Other Text
Foo-Bar: Even More Text