Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.nio.Buffer;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class semanticHtml {
- public static void main(String[] args) throws IOException {
- Scanner input = new Scanner(System.in);
- List<String> lines = new ArrayList<>();
- BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
- while (true) {
- String inputLine = bf.readLine();
- if (inputLine.equals("END")) {
- break;
- }
- lines.add(inputLine);
- }
- Pattern pattern = Pattern.compile("(?<remove><div\\s*(?<front>.+)(class|id)\\s*=\\s*\"(?<target>(main|footer|header|nav|article|section|aside))\"\\s*(?<tail>[^\\s]*)\\s*>)");
- Pattern pattern2 = Pattern.compile("<\\/div>(?<remove1>\\s+<!--\\s*(?<closing>[a-z]+)\\s*-->)");
- for (int i = 0; i < lines.size(); i++) {
- Matcher matcher = pattern.matcher(lines.get(i));
- Matcher matcher2 = pattern2.matcher(lines.get(i));
- if (matcher.find()) {
- String front = matcher.group("front").trim();
- String tail = matcher.group("tail").trim();
- if(front.length() >1){
- front = " "+front;
- }
- if(tail.length() > 1){
- tail = " " + tail;
- }
- String line = lines.get(i)
- .replace(matcher.group("remove"), "<"
- + matcher.group("target") +
- front + tail + ">");
- lines.set(i, line);
- }
- if (matcher2.find()) {
- String line = lines.get(i)
- .replace("</div", "</" + matcher2.group("closing"))
- .replace(matcher2.group("remove1"), "");
- lines.set(i, line);
- }
- }
- for (String lin : lines) {
- System.out.println(lin);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement