fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Web;
  5.  
  6. public class Test
  7. {
  8. static Dictionary<string, string> HTMLAttributes(string tag)
  9. {
  10. Dictionary<string, string> attr = new Dictionary<string, string>();
  11.  
  12. MatchCollection matches = Regex.Matches(tag, @"([^\t\n\f \/>""'=]+)(?:\s*=\s*)('.*?'|"".*?"")(?:\s|\/>|\>)");
  13.  
  14. foreach (Match match in matches)
  15. {
  16. attr.Add(
  17. match.Groups[1].Value,
  18. match.Groups[2].Value.Substring(1, match.Groups[2].Value.Length - 2)
  19. // HttpUtility.HtmlDecode()
  20. );
  21. }
  22.  
  23. return attr;
  24. }
  25.  
  26. public static void Main()
  27. {
  28. Dictionary<string, string> attributes =
  29. HTMLAttributes(Console.ReadLine());
  30.  
  31. foreach(KeyValuePair<string,string> attribute in attributes)
  32. {
  33. Console.WriteLine("name : \"" + attribute.Key+"\"");
  34. Console.WriteLine("value : \"" + attribute.Value+"\"");
  35. Console.WriteLine("");
  36. }
  37. }
  38. }
Success #stdin #stdout 0.09s 34424KB
stdin
<body class = " something " hello='world' />
stdout
name : "class"
value : " something "

name : "hello"
value : "world"