我制作了一个包含数组列表的函数 Datepattern 并添加了日期模式正则表达式 我的代码如下
私有 ArrayList getDatePatterns() { ArrayList alDate = new ArrayList();
//Thursday, the 7th December, 2006.00
alDate.add("\\b(?i)(monday|tuesday|wednesday|thursday|friday|saturday|sunday)[ ]*[,][ ]*(the)[ ]*[0-9]+(st|th|rd|nd)?[ ]*(Jan[.]?|January|Feb[.]?|February|Mar[.]?|March|Apr[.]?|April|May|Jun[.]?|June|Jul[.]?|July|Aug[.]?|August|Sep[t]?[.]?|September|Oct[.]?|October|Nov[.]?|November|Dec[.]?|December)[ ]*[,][ ]*[0-9]+\\b");
//Examples: 24th July to 3rd August, 2007 24 July to 3 August, 2007
alDate.add("\\b(?i)(?:0?[1-9]|[12][0-9]|3[01])(st|th|rd|nd)?([ ])?(Jan[.]?|January|Feb[.]?|February|Mar[.]?|March|Apr[.]?|April|May|Jun[.]?|June|Jul[.]?|July|Aug[.]?|August|Sep[t]?[.]?|September|Oct[.]?|October|Nov[.]?|November|Dec[.]?|December)[ ]?(to)([ ])?(0?[1-9]|[12][0-9]|3[01])(st|th|rd|nd)?([ ])?(Jan[.]?|January|Feb[.]?|February|Mar[.]?|March|Apr[.]?|April|May|Jun[.]?|June|Jul[.]?|July|Aug[.]?|August|Sep[t]?[.]?|September|Oct[.]?|October|Nov[.]?|November|Dec[.]?|December)[ ]*[\\,]?([ ])*([0-9]+)?\\b");
//Examples: 1.4.94-to-25.1.95
// alDate.add("\\b(?i)[0-9]+[ ]*[.][ ]*[0-9]+[ ]*[.][ ]*[0-9]+[ ]*[.][ ]*(to)[ ]*[0-9]+[ ]*[.][ ]*[0-9]+[ ]*[.][ ]*[0-9]+\\b");
//Examples: 9th & 12th August, 9th and 12th August, 2008 9th to 12th August, 2008 9th/12th August, 2008 9th-12th August, 2008
//////// alDate.add("\\b(?i)(?:(from)?([ ])?0?[1-9]|[12][0-9]|3[01])[ ]*(st|th|rd|nd)?([ ])?(and|to|\\/|[\\-]|&)([ ])?(0?[1-9]|[12][0-9]|3[01])[ ]*(st|th|rd|nd)?([ ])?(of)?([ ])?(Jan[.]?|January|Feb[.]?|February|Mar[.]?|March|Apr[.]?|April|May|Jun[.]?|June|Jul[.]?|July|Aug[.]?|August|Sep[t]?[.]?|September|Oct[.]?|October|Nov[.]?|November|Dec[.]?|December)[ ]*[\\,]*([ ])?([0-9]+)?\\b");
//Example : 28th July 28 July 24 July 2007 24-July-2007 24th July, 2007 24 July, 2007 24th day of July, 2007 21st of May, 2008
alDate.add("\\b(?i)(Letter No[.]?[ |-])?(?:0?[1-9]|[12][0-9]|3[01])([\\-]|[ ])?(st|th|rd|nd)?([ ])?(day[ ]of[ ])?(of[ ])?(Jan[.]?|January|Feb[.]?|February|Mar[.]?|March|Apr[.]?|April|May|Jun[.]?|June|Jul[.]?|July|Aug[.]?|August|Sep[t]?[.]?|September|Oct[.]?|October|Nov[.]?|November|Dec[.]?|December)([ ]?[\\,]?([\\-]|[ ])?([0-9]+))\\b");
//Example : August 24, 07; November 26-30, 2007
alDate.add("\\b(?i)(?:Jan[.]?|January|Feb[.]?|February|Mar[.]?|March|Apr[.]?|April|May|Jun[.]?|June|Jul[.]?|July|Aug[.]?|August|Sep[.]?|Sept[.]?|September|Oct[.]?|October|Nov[.]?|November|Dec[.]?|December)[ ]?((0?[1-9]|[12][0-9]|3[01])[ ]?[-][ ]?)?(0?[1-9]|[12][0-9]|3[01])([ ])?[\\,]([ ])?([0-9]+)?\\b");
//June 08 and June 2008; May'08 and June'08
alDate.add("\\b(?i)(?:Jan[.]?|January|Feb[.]?|February|Mar[.]?|March|Apr[.]?|April|May|Jun[.]?|June|Jul[.]?|July|Aug[.]?|August|Sep[.]?|Sept[.]?|September|Oct[.]?|October|Nov[.]?|November|Dec[.]?|December)[ ]?([\\,\\'])?([ ])?([0-9]+)?[ ]*(and)[ ]*(?:Jan[.]?|January|Feb[.]?|February|Mar[.]?|March|Apr[.]?|April|May|Jun[.]?|June|Jul[.]?|July|Aug[.]?|August|Sep[.]?|Sept[.]?|September|Oct[.]?|October|Nov[.]?|November|Dec[.]?|December)[ ]?([\\,\\'])?([ ])?([0-9]+)?\\b");
//Example : March, 2009; March 2009; June-April, 2008
alDate.add("\\b(?i)((?:Jan[.]?|January|Feb[.]?|February|Mar[.]?|March|Apr[.]?|April|May|Jun[.]?|June|Jul[.]?|July|Aug[.]?|August|Sep[.]?|Sept[.]?|September|Oct[.]?|October|Nov[.]?|November|Dec[.]?|December)[ ]?[-][ ]?)?(?:Jan[.]?|January|Feb[.]?|February|Mar[.]?|March|Apr[.]?|April|May|Jun[.]?|June|Jul[.]?|July|Aug[.]?|August|Sep[.]?|Sept[.]?|September|Oct[.]?|October|Nov[.]?|November|Dec[.]?|December)[ ]?([\\,])?([ ])?[0-9]+\\b");
//Examples: from dd-mm-yy to dd-mm-yy dd/mm/yy , dd.mm.yy etc
// alDate.add("\\b(?i)(i[.]e[.]|viz[.]|means)\\s(from[ ])(0?[1-9]|[12][0-9]|3[01])([\\.]|[\\-]|[ \\/])+(?:0?[1-9]|1[0|1|2])([\\.]|[\\-]|[ \\/])+[0-9]+([ ]to[ ])(?:0?[1-9]|[12][0-9]|3[01])([\\.]|[\\-]|[ \\/])+(?:0?[1-9]|1[0|1|2])([\\.]|[\\-]|[ \\/])+[0-9]+\\b");
// alDate.add("\\b(?i)(from[ ])(0?[1-9]|[12][0-9]|3[01])([\\.]|[\\-]|[ \\/])+(?:0?[1-9]|1[0|1|2])([\\.]|[\\-]|[ \\/])+[0-9]+([ ]to[ ])(?:0?[1-9]|[12][0-9]|3[01])([\\.]|[\\-]|[ \\/])+(?:0?[1-9]|1[0|1|2])([\\.]|[\\-]|[ \\/])+[0-9]+\\b");
// 28th Feburary
alDate.add("\\b(?i)(the)?[ ]*[0-9]+(st|th|rd|nd)?[ ]*(Jan[.]?|January|February|Feb[.]?|Mar[.]?|March|Apr[.]?|April|May|Jun[.]?|June|Jul[.]?|July|Aug[.]?|August|Sep[t]?[.]?|September|Oct[.]?|October|Nov[.]?|November|Dec[.]?|December)");
//Examples: dd-mm-yy , dd/mm/yy , dd.mm.yy etc
alDate.add("\\b(?i)(?:0?[1-9]|[12][0-9]|3[01])([\\.]|[\\-]|[ \\/])+(?:0?[1-9]|1[0|1|2])([\\.]|[\\-]|[ \\/])+[0-9]+\\b");
//2002-2003
//alDate.add("\\b([0-9]+[\\-][0-9]+)\\b");
return alDate;
}
而不是这个,我想要一个满足上述所有条件的正则表达式。在评论中我提到了正则表达式遵循的日期模式。任何人都可以帮助我,我想为日期模式编写一个单一的正则表达式,而不是这个大代码。我想减少代码。感谢你