Tag Content Extractor

Sort by

recency

|

213 Discussions

|

  • + 0 comments
    Pattern p = Pattern.compile("<(.+)>([^<]+)</\\1>");
    Matcher m  = p.matcher(line);
    if (m.find()){
        do {System.out.println(m.group(2));}
         while (m.find());
                }
    else{System.out.println("None");}
    
  • + 0 comments

    **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());
        while(testCases>0 && in.hasNextLine()){
            String line = in.nextLine();
            String[] lines = line.split("\n");
            for (String string : lines) {
                String regex = "<(.+)>([^<>]+)</\\1>";
                Pattern pattern = Pattern.compile(regex);
                Matcher matcher = pattern.matcher(string); 
                while (matcher.find()) {
                    String match = matcher.group(2);
                    System.out.println(match);             
                }
    
                matcher.reset();
    
                if (matcher.find() == false) {
                    System.out.println("None");
                }
            }
            testCases--;
        }
        in.close();
    }
    

    }**

  • + 0 comments

    Scanner in = new Scanner(System.in); int testCases = Integer.parseInt(in.nextLine()); while(testCases>0){ String line = in.nextLine();

            Pattern pattern = Pattern.compile("<(.+)>([^<]+)</\\1>");
            Matcher m = pattern.matcher(line);
    
            boolean found = false;
            while(m.find()) {
                System.out.println(m.group(2));
                found = true;
            }
            if(!found) {
                System.out.println("None");
            }
    
            testCases--;
        }
    
  • + 0 comments

    import java.io.; import java.util.; 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()); // Read number of test cases
    
        while(testCases > 0) {
            String line = in.nextLine(); // Read each line
            boolean patternMatch = false; // Flag to check if any pattern matches
    
            // Define the regex pattern to match HTML tags and capture the content between them
            Pattern pattern = Pattern.compile("<(.+?)>([^<>]+)</\\1>");
            Matcher matcher = pattern.matcher(line);
    
            // Iterate through all the matches found in the line
            while(matcher.find()) {
                System.out.println(matcher.group(2)); // Print the content between the tags
                patternMatch = true; // Set flag to true if a pattern match is found
            }
    
            if(!patternMatch) {
                System.out.println("None"); // Print "None" if no matches are found
            }
    
            testCases--; // Decrement the test case count
        }
        in.close(); // Close the scanner
    }
    

    }

  • + 0 comments
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        scanner.nextLine();
        for(int i=0; i<n; i++){ 
            String input = scanner.nextLine();
            String reg = "<([^<>]+)>([^<>]+)</\\1>";
            Pattern pattern = Pattern.compile(reg);
            Matcher matcher = pattern.matcher(input);
    
                if(!(matcher.find())){
                    System.out.println("None");
                }
                matcher = pattern.matcher(input);
                while(matcher.find()){
                    String matchStr = matcher.group(2);
                    Matcher matcher2 = pattern.matcher(matchStr);
                    while(matcher2.find()){
                        matchStr = matcher2.group(2);
                        matcher2 = pattern.matcher(matchStr);
                    }
                    System.out.println(matchStr);
                    }
                }