I am using regex to figure out what format the input date is. This is one of the patterns i am using
^((18[5-9]|19[0-9]|20[0-9])\\d)(0?[1-9]|1[012])(0?[1-9]|[12][0-9]|3[01])$
so the constraint is to have the year between 1850 and 2099. If I pass for instance this string as date 20011212 when I am extracting the year, month and day from it, this is what I get: year: 2001, month: 200, day :12. Any Idea why?
pattern = Pattern.compile(PATTERN);
matcher = pattern.matcher(dateString);
if (matcher.matches()){
matcher.reset();
if (matcher.find()){
Integer.parseInt(matcher.group(1));
Integer.parseInt(matcher.group(2));
Integer.parseInt(matcher.group(3));
}
}
The code is simplified, but even on this simplified version, it returns erroneous results. Thank you for any suggestions/solutions.