Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.regex.MatchResult;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- import java.util.stream.IntStream;
- import java.util.stream.Stream;
- public class Test {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- for (int i = 1; i <= n; i++) {
- String text = scanner.nextLine();
- String regexName = "@(?<name>[A-Za-z]+)\\|";
- String regexAge = "#(?<age>[0-9]+)\\*";
- Pattern patternName = Pattern.compile(regexName);
- Matcher matcherName = patternName.matcher(text);
- Pattern patternAge = Pattern.compile(regexAge);
- Matcher matcherAge = patternAge.matcher(text);
- while (matcherName.find() && matcherAge.find()) {
- String name = matcherName.group("name");
- String age = matcherName.group("age");
- System.out.printf("%s is %s years old.",name,age);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement