-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathSolution.java
More file actions
30 lines (26 loc) · 841 Bytes
/
Solution.java
File metadata and controls
30 lines (26 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Solution{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int numberOfTestCases = Integer.parseInt(in.nextLine());
for (int i = 0; i< numberOfTestCases; i++) {
String line = in.nextLine();
printContentEnclosedWithinTags(line);
}
in.close();
}
public static void printContentEnclosedWithinTags(String line) {
Pattern pattern = Pattern.compile("<(.+)>([^<]+)</\\1>");
Matcher matcher = pattern.matcher(line);
boolean matchFound = false;
while (matcher.find()) {
System.out.println(matcher.group(2));
matchFound = true;
}
if (!matchFound) {
System.out.println("None");
}
}
}