带闰年判断的正则表达式

 首先,你的年的范围是1800-3999
润年:
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)";
其他的0结尾的:
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))";
润年2月:
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))";
把上面4种正则表达式用|连接,然后加上润年的2月和其他月份的处理:
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))";
非润年2月:
String month = "(02-(([0-2][1-9])|([1-2]0)))";
把上面3种正则表达式用|连接,然后加上非润年2月和其他月份的处理:
String noleap = "(" + noleap1 + "|" + noleap2 + "|" + noleap3 + ")-("
                + month + "|" + other1 + "|" + other2 + ")";
  

润年和非润年的正则表达式的组合就是了:
String yearregex = leap + "|" + noleap;

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值