We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tag Content Extractor
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.; import java.util.regex.*;
public class Solution { public static void main(String[] args) {
}