fork download
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var text = "[{PRE.Word1.Word2}] and [{PRE.Word 3.Word..... 2 %%%}]";
  12. var pattern = @"\[{PRE\.([^][{}.]{1,15})\.(.{1,64}?)}]";
  13. var matches = Regex.Matches(text, pattern);
  14. var props = new List<Property>();
  15. foreach (Match m in matches)
  16. props.Add(new Property(m.Groups[1].Value,m.Groups[2].Value));
  17.  
  18. foreach (var item in props)
  19. Console.WriteLine("Word1 = " + item.Word1 + ", Word2 = " + item.Word2);
  20. }
  21.  
  22. public class Property
  23. {
  24. public string Word1 { get; set; }
  25. public string Word2 { get; set; }
  26. public Property()
  27. {}
  28. public Property(string w1, string w2)
  29. {
  30. this.Word1 = w1;
  31. this.Word2 = w2;
  32. }
  33. }
  34. }
Success #stdin #stdout 0.1s 29608KB
stdin
Standard input is empty
stdout
Word1 = Word1, Word2 = Word2
Word1 = Word 3, Word2 = Word..... 2 %%%