Advertisement
petar088

Rage Quit2

May 7th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. package Fundamentals._28_Text_Regex_Exercise.More_Exercise;
  2.  
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class _7_Rage_Quit {
  8. public static void main(String[] args) {
  9. Scanner sc = new Scanner(System.in);
  10.  
  11. String input = sc.nextLine();
  12. String regex = "[^\\d\\s]*(?<numb>[\\d]{0,2})[^\\d\\s]*";
  13.  
  14. Pattern pattern = Pattern.compile(regex);
  15. Matcher matcher = pattern.matcher(input);
  16.  
  17. while (matcher.find()){
  18.  
  19.  
  20. int num = Integer.parseInt(matcher.group("numb"));
  21. String foIndex = String.valueOf(num);
  22. System.out.println(num);
  23. int index = input.indexOf(foIndex);
  24. System.out.println(index);
  25.  
  26.  
  27. }
  28.  
  29.  
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement