I'm trying to extract four digits before the file extension using Java Pattern Matchers. It's throwing no group found exception. Can someone help me on this ?
String fileName = "20210101-000000_first_second_1234.csv";
Pattern pattern = Pattern.compile("\\\\d{4}");
System.out.println(pattern.matcher(fileName).group(4));
I would like to get 1234 from the fileName. I compiled the file pattern using regex \\\\d{4}. Which returns four groups. So, fourth group should suppose to return 1234 which is not returning, instead throwing group not found exception.