Hackerrank - Java Solution - Tag Content Extractor Solution
Problem Link - Tag Content Extractor
Level - String
Java Code
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int testCases = Integer.parseInt(scan.nextLine());
/* Solution assumes we can't have the symbol "<" as text between tags */
while (testCases-- > 0) {
String line = scan.nextLine();
boolean matchFound = false;
Pattern r = Pattern.compile("<(.+)>([^<]+)</\\1>");
Matcher m = r.matcher(line);
while (m.find()) {
System.out.println(m.group(2));
matchFound = true;
}
if (!matchFound) {
System.out.println("None");
}
}
scan.close();
}
}
Tags: HackerRank Online Judge Solution, HackerRank OJ Solution list, HackerRank Problems Solution, HackerRank solver, HackerRank all problem solution list, HackerRank solution in java, Hackerrank Java Solution, Hackerrank - Java Solution - Tag Content Extractor Solution, Hackerrank Online Judge Solution, Hackerrank - Java Solutions,
No comments:
Post a Comment