Advertisement
Guest User

Untitled

a guest
May 26th, 2015
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace SemanticHtml
  9. {
  10. class SemanticHtml
  11. {
  12. static void Main()
  13. {
  14. var row = Console.ReadLine();
  15. var openTagPattern = @"<div(.*)(id|class)\s*=\s*""(\w+)""(.*)>";
  16. var closeTagPattern = @"</div>(\s*<!--\s*(\w+)\s*-->)";
  17. while (row != "END")
  18. {
  19. if (Regex.IsMatch(row, openTagPattern))
  20. {
  21. var matches = Regex.Match(row, @"\s(id|class)\s*=\s*""(\w+)""");
  22. var tagName = matches.Groups[2].Value.Trim();
  23. var attribute = matches.Groups[0].Value;
  24. var result = row.Replace("div", tagName);
  25. result = result.Replace(attribute, "");
  26. result = result.Replace(" ", " ");
  27. result = result.Replace(" >", ">");
  28. Console.WriteLine(result);
  29.  
  30.  
  31. }
  32. else if(Regex.IsMatch(row, closeTagPattern)){
  33. var mathes = Regex.Match(row, closeTagPattern);
  34. var tagname = mathes.Groups[2].Value;
  35. var comment = mathes.Groups[1].Value;
  36. var result = row.Replace(comment, "");
  37. result = result.Replace("div", tagname);
  38. Console.WriteLine(result);
  39. }
  40. else {
  41. Console.WriteLine(row);
  42. }
  43. row = Console.ReadLine();
  44. }
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement