Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class _03_ExtractFile {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- String regName = "(?<=\\\\)\\b[\\w.-]+\\b(?=\\.)";
- String regExt = "(?<=\\.)\\b[a-z]+\\b(?!.)";
- Pattern p1 = Pattern.compile(regName);
- Matcher m1 = p1.matcher(input);
- String name = "";
- if(m1.find()){
- name = m1.group();
- }
- Pattern p2 = Pattern.compile(regExt);
- Matcher m2 = p2.matcher(input);
- String ext = "";
- if(m2.find()){
- ext = m2.group();
- }
- System.out.println("File name: " + name);
- System.out.println("File extension: " + ext);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement