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 = "field1 : value1a value1b field2 : value2a value2b";
  9. var matches = Regex.Matches(text, @"(\w+)\s*:\s*(.*?)(?=\s*\w+\s*:|$)");
  10. foreach (Match m in matches)
  11. {
  12. Console.WriteLine("-- MATCH FOUND --\nKey: {0}, Value: {1}",
  13. m.Groups[1].Value, m.Groups[2].Value);
  14. }
  15. }
  16. }
Success #stdin #stdout 0.08s 29808KB
stdin
Standard input is empty
stdout
-- MATCH FOUND --
Key: field1, Value: value1a  value1b
-- MATCH FOUND --
Key: field2, Value: value2a value2b