### Question:
DateFromString { public static Date getDateUsingRegExpAndDateFormat(String dateString, String matchPattern, String substitutionPattern, String dateFormatString) { Pattern pattern = Pattern.compile(matchPattern); Matcher matcher = pattern.matcher(dateString); if (!matcher.matches()) { return null; } StringBuffer dateStringFormatted = new StringBuffer(); matcher.appendReplacement(dateStringFormatted, substitutionPattern); if (dateStringFormatted.length() == 0) { return null; } return getDateUsingCompleteDateFormat(dateStringFormatted.toString(), dateFormatString); }  static Date getDateUsingSimpleDateFormat(String dateString, String dateFormatString); static Date getDateUsingDemarkatedCount(String dateString, String dateFormatString, char demark); static Date getDateUsingDemarkatedMatch(String dateString, String dateFormatString, char demark); static Date getDateUsingCompleteDateFormat(String dateString, String dateFormatString); static Date getDateUsingCompleteDateFormatWithOffset(String dateString, String dateFormatString,
      int startIndex); static Date getDateUsingRegExp(String dateString, String matchPattern, String substitutionPattern); static Date getDateUsingRegExpAndDateFormat(String dateString, String matchPattern, String substitutionPattern,
      String dateFormatString);  }### Answer:
@Test public void testGetDateUsingRegExpAndDateFormat() { String matchPattern = ".*([0-9]{4})([0-9]{2})([0-9]{2})_([0-9]{2})([0-9]{2}).*grib"; String substitutionPattern = "$1$2$3_$4$5"; String dateFormatString = "yyyyMMdd_HHmm"; Date date = DateFromString.getDateUsingRegExpAndDateFormat(fileName, matchPattern, substitutionPattern, dateFormatString); Assert.assertEquals( "Calculated date <" + date.toString() + " [" + date.getTime() + "]> not as expected <" + dateAsISOString + "[" + dateAsLong + "]>." + "\nUsing fileName <" + fileName + ">, matchPattern <" + matchPattern + ">, substitutionPattern <" + substitutionPattern + ">, and dateFormatString <" + dateFormatString + ">", date.getTime(), dateAsLong); }