Created
September 25, 2011 13:31
-
-
Save Zegnat/1240601 to your computer and use it in GitHub Desktop.
Regular expression for ISO 8601 datestamps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
^ | |
(\+|-)? # Extended year? | |
(\d{4,}) # Year | |
( | |
( | |
-? # Optional separator | |
(0[1-9]|1[012]) # Month, 01 to 12 | |
(?(?<=-\d\d)-) # Require another separator if we used one before | |
(0[1-9]|[12][0-9]|3[01]) # Day, 01 to 31 | |
)|( | |
-? # Optional separator | |
(00[1-9]|0[1-9]\d|[12]\d\d|3[0-5]\d|36[0-6]) # Ordinal day, 001 to 366 | |
) | |
) | |
-(.*) # Required separator and slug | |
(\.[^.]+) # Required file extension | |
$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby does not do the conditional capturing group. | |
^ | |
(\+|-)? # Extended year? | |
(\d{4,}) # Year | |
( | |
( | |
( | |
-(0[1-9]|1[012])- # Month, 01 to 12, with separators | |
| | |
(0[1-9]|1[012]) # Month, 01 to 12, without separators | |
) | |
(0[1-9]|[12][0-9]|3[01]) # Day, 01 to 31 | |
)|( | |
-? # Optional separator | |
(00[1-9]|0[1-9]\d|[12]\d\d|3[0-5]\d|36[0-6]) # Ordinal day, 001 to 366 | |
) | |
) | |
-(.*) # Required separator and slug | |
(\.[^.]+) # Required file extension | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment