Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Fundamentals._28_Text_Regex_Exercise.More_Exercise;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class _7_Rage_Quit {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String input = sc.nextLine();
- String regex = "[^\\d]*(?<number>[\\d]*)[^\\d]*";
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(input);
- while (matcher.find()){
- int num = Integer.parseInt(matcher.group("number"));
- String foIndex = String.valueOf(num);
- System.out.println(num);
- int index = input.indexOf(foIndex);
- System.out.println(index);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement