Tag Content Extractor

  • + 0 comments
    import javax.swing.text.StyledEditorKit;
    import java.io.*;
    import java.util.*;
    import java.text.*;
    import java.math.*;
    import java.util.regex.*;
    
    public class Solution {
        public static void main(String[] args) {
    
            Scanner in = new Scanner(System.in);
            int testCases = Integer.parseInt(in.nextLine());
            Pattern pattern = Pattern.compile("<(.+)>([^<>]+)</\\1>");
            for (int i = 0; i < testCases; i++) {
                boolean matched = false;
                String string = in.nextLine();
                Matcher matcher = pattern.matcher(string);
                while (matcher.find()) {
                    System.out.println(matcher.group(2));
                    matched = true;
                }
                if (!matched) {
                    System.out.println("None");
                }
            }
        }
    }