Created
August 6, 2014 09:59
-
-
Save pscollins/edc983d1ed989ac03bc7 to your computer and use it in GitHub Desktop.
regex strangeness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Calendar startCalendarFromFilename(String bookPath) { | |
// format is YYYYMMDD | |
String datePattern = "\\D+(\\d{4})(\\d{2})(\\d{2})\\.csv\\.gz"; | |
Pattern dateRe = Pattern.compile(datePattern); | |
Matcher matcher = dateRe.matcher(bookPath); | |
Calendar startDate; | |
if (matcher.groupCount() == 3) { | |
System.out.println("Got match on:" + matcher.toString()); | |
System.out.println("Group 0:" + matcher.group(0)); | |
startDate = Calendar.getInstance(); | |
startDate.set(Integer.valueOf(matcher.group(1)), | |
Integer.valueOf(matcher.group(2)), | |
Integer.valueOf(matcher.group(3))); | |
return startDate; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment