final String timeFrag = "((?:T| )(?:(?:[01][0-9]|2[0-3]):(?:[0-5][0-9]):(?:[0-5][0-9])(?:\\.[0-9]+)?|(?:24:00:00(?:\\.0+)?)))?"; // Group 2
final String timeZoneFrag = "(Z|(?:\\+|-)(?:(?:0[0-9]|1[0-3]):[0-5][0-9]|14:00))?"; // Group 3
String pattern = "^" + yearMonthDayFrag + timeFrag + timeZoneFrag + "$";
RegExp regExp = RegExp.compile(pattern);
MatchResult matchResult = regExp.exec(lexicalValue);
if(matchResult == null) {
throw new IllegalArgumentException();
}
String matchedYearMonthDay = matchResult.getGroup(1);
String matchedTime = matchResult.getGroup(2);