deyanmalinov

03. Extract File + regex

Mar 25th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class Main {
  8.         public static void main(String[] args) {
  9.             Scanner scan = new Scanner(System.in);
  10.             String line = scan.nextLine();
  11.             List<String> file = Arrays.asList(line.substring(line.lastIndexOf("\\") + 1).split("\\."));
  12.             String nFile = String.join(".", file.subList(0, file.size()-1));
  13.             String ext = file.get(file.size()-1);
  14.  
  15.  
  16.             System.out.println("File name: " + nFile);
  17.             System.out.println("File extension: " + ext);
  18. ////////////////////////////////////////
  19. //            String regex = "(.*)\\.(.*)";
  20. //
  21. //
  22. //            Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
  23. //            Matcher matcher = pattern.matcher(file);
  24. //
  25. //            if (matcher.find()) {
  26. //                System.out.println("File name: " + matcher.group(1));
  27. //                System.out.println("File extension: " + matcher.group(2));
  28. //            }
  29. ///////////////////////////////////////
  30.         }
  31. }
Add Comment
Please, Sign In to add comment