Advertisement
deyanmalinov

05. Digits, Letters and Other

Mar 23rd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.LinkedList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. public class Main {
  10.         public static void main(String[] args) {
  11.             Scanner scan = new Scanner(System.in);
  12.             String string = scan.nextLine();
  13.             String regex = "(?<buk>[a-zA-Z]+)?(?<nish>[\\W]+)?(?<cif>[\\d]+)";
  14.             Pattern pattern = Pattern.compile(regex);
  15.             Matcher line = pattern.matcher(string);
  16.             List<String> buk = new LinkedList<>();
  17.             List<String> cif = new LinkedList<>();
  18.             List<String> nish = new LinkedList<>();
  19.  
  20.             while (line.find()) {
  21.                 buk.add(line.group("buk"));
  22.                 cif.add(line.group("cif"));
  23.                nish.add(line.group("nish"));
  24.  
  25.             }
  26.             System.out.println(cif.toString().replaceAll(", ", "").replaceAll("\\[|\\]", ""));
  27.             System.out.println(buk.toString().replaceAll(", ", "").replaceAll("\\[|\\]", ""));
  28.             System.out.println(nish.toString().replaceAll(", ", "").replaceAll("\\[|\\]", "").replaceAll("null", ""));
  29.  
  30.         }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement