Input Format

The first line of input contains a single integer,  (the number of lines).
The  subsequent lines each contain a line of text.


  • Each line contains a maximum of  printable characters.
  • The total number of characters in all test cases will not exceed .

Output Format

For each line, print the content enclosed within valid tags.
If a line contains multiple instances of valid content, print out each instance of valid content on a new line; if no valid content is found, print None.

hackerrank tag content extractor solution in java

Tag Content Extractor problem solution in java | HackerRank

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Solution
    public static void main(String[] args){

        String pattern = "<([^>]+)>([^<>]+)</\\1>";
        Pattern r = Pattern.compile(pattern);

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

            Matcher m = r.matcher(line);
            boolean findMatch = true;
            while(m.find( )){
                findMatch = false;
            if(findMatch) {