Guest User

Untitled

a guest
May 30th, 2015
276
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6.  
  7. class SemanticHTML
  8. {
  9.     static void Main()
  10.     {
  11.         string openPattern = @"( *?)<div\s+(.*?)(?:id|class)\s*?=\s*?""(.+?)""\s*(.*?)>";
  12.         string closePattern = @"(\s*?)<\/div>\s*<!--\s*([a-z]+)\s*-->";
  13.         string input = Console.ReadLine();
  14.         while (input !="END")
  15.         {
  16.             string line = input;
  17.             if (Regex.IsMatch(input, openPattern))
  18.             {
  19.                 Match match = Regex.Match(input, openPattern);
  20.                 line = string.Format("{0}<{1} {2} {3}", match.Groups[1], match.Groups[2], match.Groups[3], match.Groups[4]).TrimEnd() + ">";
  21.                 line = Regex.Replace(line, @"(?<=<.*?)\s{2,}", " ");
  22.             }
  23.             else if (Regex.IsMatch(input, closePattern))
  24.             {
  25.                 Match match = Regex.Match(input, closePattern);
  26.                 line = string.Format("{0}</{1}>", match.Groups[1], match.Groups[2]);
  27.             }
  28.             Console.WriteLine(line);
  29.             input = Console.ReadLine();
  30.         }
  31.     }
  32. }
RAW Paste Data