fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var str =
  10. @"namespace MyNameSpace
  11. {
  12. [MyAttribute]
  13. public class MyClass
  14. {
  15.  
  16. [MyPropertyAttribute(DefaultValue = ""Default Value 1"")]
  17. public static string MyProperty1
  18. {
  19. get { return ""hello1""; }
  20. }
  21.  
  22. [MyPropertyAttribute(DefaultValue = ""Default Value 2"")]
  23. public static string MyProperty2
  24. {
  25. get { return ""hello2""; }
  26. }
  27.  
  28. }
  29. }";
  30.  
  31. var regex =
  32. @"\[MyPropertyAttribute\(DefaultValue = ""([^""]+)""\)\]" +
  33. @"\s+public static string ([a-zA-Z0-9]+)";
  34.  
  35. var matches = Regex.Matches(str, regex);
  36.  
  37. foreach (var match in matches.Cast<Match>()) {
  38. Console.WriteLine(string.Format("{{\"{0}\", \"{1}\"}}", match.Groups[2].Value, match.Groups[1].Value));
  39. }
  40. }
  41. }
Success #stdin #stdout 0.08s 34208KB
stdin
Standard input is empty
stdout
{"MyProperty1", "Default Value 1"}
{"MyProperty2", "Default Value 2"}