Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- class Semantic
- {
- static void Main()
- {
- var openTagRegex = new Regex(@"<div.*?((?:id|class)\s*=\s*""(\w+?)"").*?>");
- var closeTagRegex = new Regex(@"<\/div>(\s*<!--\s*(\w+?)\s*-->)");
- string input;
- while ((input = Console.ReadLine()) != "END")
- {
- var output = input;
- //modify opening tags
- var match = openTagRegex.Match(input);
- if (match.Success)
- {
- output = input.Replace("div", match.Groups[2].Value);
- output = output.Replace(match.Groups[1].Value, "");
- output = Regex.Replace(output, @"\s+>", ">");
- output = Regex.Replace(output, @"\s+", " ");
- }
- //closing tags
- match = closeTagRegex.Match(input);
- if (match.Success)
- {
- output = output.Replace(match.Groups[1].Value, "");
- output = output.Replace("div", match.Groups[2].Value);
- }
- Console.WriteLine(output);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement