[QA] How to use regular expression to find year, month and day of date

String aDate = "date: 04-16-2013";
Pattern datePattern = Pattern.compile("date: (\\d{2})-(\\d{2})-(\\d{4})");
Matcher dateMatcher = datePattern.matcher(aDate);
if (dateMatcher.find()) {
   System.out.println("Month is: " + dateMatcher.group(1));
   System.out.println("Day is: " + dateMatcher.group(2));
   System.out.println("Year is: " + dateMatcher.group(3));
}
Tags : ,

0 thoughts on “[QA] How to use regular expression to find year, month and day of date”

Leave a Reply

Your email address will not be published. Required fields are marked *


× 7 = twenty eight