## CSDN博客

### 带闰年判断的正则表达式

1800，1900，2100，2200，2300，2500，2600，2700，2900，3000，3100，3300，3400，3500，3700，3800，3900是个特殊值(能被4整除但不是润年)，要分出来:
String leap1 = "(((1[8-9])|([2-3][0-9]))(0|2|4|6|8)(4|8))";
String leap2 = "(((2(0|4|8))|(3(2|6)))00)";

String leap3 = "(((1[8-9])|([2-3][0-9]))(2|4|6|8)0)";
2,6结尾的：
String leap4 = "(((1[8-9])|([2-3][0-9]))(1|3|5|7|9)(2|6))";

String leapmonth = "(02-(([0-1][1-9])|(10)|(2[0-8])))";

String other1 = "(((01)|(0[3-9])|(1[0-2]))-(([0-2][1-9])|([1-3]0)))";
String other2 = "(((0(1|3|5|7|8))|(10)|(12))-(31))";

String leap = "(" + leap1 + "|" + leap2 + "|" + leap3 + "|" + leap4 + ")-("
+ leapmonth + "|" + other1 + "|" + other2 + ")";

String noleap1 = "(((1[8-9])|([2-3][0-9]))(0|2|4|6|8)(1|2|3|5|6|7|9))";
String noleap2 = "(((1[8-9])|(2(1|2|3|5|6|7|9))|(3(0|1|3|4|5|7|8|9)))00)";
String noleap3 = "(((1[8-9])|([2-3][0-9]))(1|3|5|7|9)(0|1|3|4|5|7|8|9))";

String month = "(02-(([0-2][1-9])|([1-2]0)))";

String noleap = "(" + noleap1 + "|" + noleap2 + "|" + noleap3 + ")-("
+ month + "|" + other1 + "|" + other2 + ")";

String yearregex = leap + "|" + noleap;

0 0