这有点宽容,但在大多数情况下应该可以工作:
String resultString = null;
try {
Pattern regex = Pattern.compile("(\\w+,\\s+\\w+\\s+\\d{1,2},\\s+\\d{4}\\s+from\\s+\\d{1,2}:\\d{1,2}\\s+AM\\s+to\\s+\\d{1,2}:\\d{1,2}\\s+PM)",
Pattern.CANON_EQ | Pattern.DOTALL);
Matcher regexMatcher = regex.matcher(subjectString);
if (regexMatcher.find()) {
resultString = regexMatcher.group();
}
} catch (PatternSyntaxException ex) {
// Syntax error in the regular expression
}
这个检查月份名称和工作日名称:
Pattern regex = Pattern.compile("((?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday),\\s+(?:January|February|March|April|May|June|July|August|September|October|November|December)\\s+\\d{1,2},\\s+\\d{4}\\s+from\\s+\\d{1,2}:\\d{1,2}\\s+AM\\s+to\\s+\\d{1,2}:\\d{1,2}\\s+PM)",
Pattern.CANON_EQ | Pattern.DOTALL);