Tag Content Extractor

  • + 0 comments

    My code passed all test case

    import java.io.*;
    import java.util.*;
    import java.util.regex.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            Pattern p = Pattern.compile("<(.+)>([^<]+)</\\1>");
            
            Scanner input = new Scanner(System.in);
            int n = Integer.parseInt(input.nextLine());
            
            while(n-- > 0){
                String textStr = input.nextLine();
                Matcher m = p.matcher(textStr);
                boolean found = false;
                
                while(m.find()){
                    System.out.println(m.group(2));
                    found =true;
                }
                if(!found){
                    System.out.println("None");
                }
            }
        }
    }