Hello everyone,
I am new to Regular expression, and would like some hints, please if someone can direct me to right place.
I have a bunch of files in a directory, and i need to rename them based on certain pattern. I think I need to use regular expression to parse out file name and see if the file name matches my pattern and then change the file name accordingly.
Here's the scenario.
Original File Name: 220-X F-30300-8701_MAR__000_v00_TIL.pdf
The pattern I am looking for is this: ###_v##_TIL.pdf
3 consequetive digit (numbers), underscore, litter v (upper case or lower), ## (2 digits), literal _TIL.pdf
String str = "220-X F-30300-8701_MAR_001_v00_TIL.pdf";
String reg = "^\\d{3}_v\\d{2}_TIL.pdf";
Pattern regex = Pattern.compile(reg, Pattern.COMMENTS);
Matcher regexMatcher = regex.matcher(str);
boolean result = regexMatcher.matches();
System.out.println("Result = " + result);
output
--------
Result = false
It appears that it can't find the match. Am I missing something?