A regex for years
1:43pm, 9th April 2007
Because of this site’s technical history, and my commitment to unchanging URIs, the software which serves certain pages is governed, in part, by this regular expression:
^/(200[6-9]|20[1-9]\d|2[1-9]\d\d|[3-9]\d\d\d|\d{5,})/$
It’s supposed to match any year from 2006 onwards, but there must be a better way of doing it. According to the mod_rewrite documentation, there is a special extension to the regex syntax which lets you compare the TestString to a pattern lexicographically (i.e. in dictionary order), like this:
RewriteCond %{REQUEST_URI} >/2005/
If the %{REQUEST_URI} is /2006/, then shouldn’t this condition be true? Does /2006/ not lexicographically follow /2005/? Python says so:
>>> "/2006/" > "/2005/"
True
>>> "/2006/" < "/2005/"
False
Is this a definition of lexicographic ordering that mod_rewrite is unfamiliar with?
