RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Leap Year
Expression
(15(8[48]|9[26]))|((1[6-9]|[2-9]\d)(0[48]|[13579][26]|[2468][048]))|(([2468][048]|16|3579[26])00)
Description
Validates four-digit leap years after 1582 (when Pope Gregory XIII switched to the Gregorian calendar). The last recognized leap year is 9996, so no worries with the y3k bug.
Matches
1584, 2000, 2048
Non-Matches
1200, 1580, 1941, 1800
Author Rating: The rating for this expression. Jon Gray
Source
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Fixed
Name: Jon Gray
Date: 8/8/2007 10:45:19 AM
Comment:
Per Michael's comment, the regex was changed to only validate leap years after and including 1584. Thanks!


Title: Not Quite
Name: Michael Ash
Date: 7/24/2007 10:30:20 AM
Comment:
1200 and 1204 aren't really leap years. Leap years didn't begin until the late 16th century. Here a link dealing the leap year regex http://regexadvice.com/blogs/mash/archive/2004/04/02/300.aspx


Copyright © 2001-2018, RegexAdvice.com | ASP.NET Tutorials