Regular Expression with leap year judgment

Source: Internet
Author: User

Author: Xixigongzhu (Princess Xi)Http://search.csdn.net/Expert/topic/1974/1974227.xml? Temp =. 6640131.

First, your year range is 1800-3999
Runnian:
1800,1900, 2100,2200, 2300,2500, 2600,2700, 2900,3000, 3100,3300, 3400,3500, 3700,3800, 3900 is a special value (which can be divisible by four but not a runner-up:
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 )";
Other 0 ends:
String leap3 = "(1 [8-9]) | ([2-3] [0-9]) (2 | 4 | 6 | 8) 0) ";
Ended with 2, 6:
String leader = "(1 [8-9]) | ([2-3] [0-9]) (1 | 3 | 5 | 7 | 9) (2 | 6 ))";
February:
String leapmonth = "(02-([0-1] [1-9]) | (10) | (2 [0-8])";
Other months:
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 ))";
Use | to connect the above four regular expressions, and then add the processing of the first month of the last year and the other months:
String leap = "(" + leap1 + "|" + leap2 + "|" + leap3 + "|" + leap + ")-("
+ Leapmonth + "|" + other1 + "|" + other2 + ")";

Non-Profit Year:
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 ))";
Non-profit year February:
String month = "(02-([0-2] [1-9]) | ([1-2] 0 )))";
Use | to connect the above three regular expressions, and then add the processing of the non-runner-up year on January 1, February and other months:
String noleap = "(" + noleap1 + "|" + noleap2 + "|" + noleap3 + ")-("
+ Month + "|" + other1 + "|" + other2 + ")";

The combination of runnian and non-runnian regular expressions is:
String yearregex = leap + "|" + noleap;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.