Regular expression - How to translate it?
Can you translate something for me? My boyfriend is a programmer and has posted a message that I can't understand at all.
^((((31\/(0?[13578]|1[02]))|((29|30)\/(0?[1,3-9]|1[0-2])))\/(1[6-9]|[2-9]\d)?\d{2})|(29\/0?2\/(((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))|(0?[1-9]|1\d|2[0-8])\/((0?[1-9])|(1[0-2]))\/((1[6-9]|[2-9]\d)?\d{2})) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$
What does it mean? Is it a normal mes开发者_StackOverflow社区sage with words or is it some kind of other code?
It's an expression that attempts to match all valid date/times in d/m/y H:M:S
format, with or without leading zeros, and using 2- or 4-digit years, including Feb 29 on leap years. Not sure why he'd be sending you this, unless the context of your conversation makes it relevant somehow.
It'd match:
- the 31st day of January, March, May, July, August, October, or December, or the 29th or 30th days of any month but February, in any year from 1600 to 9999;
- the 29th day of February in any multiple-of-4-but-not-100 year from 1604 to 9996, or multiple-of-400 years from 1600 to 9600;
- or day 1-28 in any month in any year from 1600 to 9999;
plus a time in 24-hour format.
Looks like he didn't account for leap seconds. Bad boy.
EDIT:
Looking over the regex again, it also looks like it won't match 29/2/00 00:00:00
. The leap year match for multiple-of-400 years doesn't take 2-digit years into account. It really can't do so in a way that won't break in 80 years or so (or whenever 00
starts to mean 2100 and not 2000), unless he wants to define 00
as meaning 2000 for the expected life of the software and risk a very subtle Y2.1K bug if it lives that long.
精彩评论