regular expressions for timestamps
I'm trying to create a regex for a timestamp which could be formatted like this
2011-12-31T23:00:0开发者_JS百科0.000+01:00
My closest solution I can think of is:
/^(\d{4})-(\d\d)-(\d\d)T:(\d\d):(\d\d).(\d{3})+(\d\d):(\d\d)$/
But that doesn't seem to work.
Any suggestions on where I went wrong? (I'm using this in php preg_match() )
Thanks
It doesn't work because you have T:
in your regex, yet no T:
in your timestamp. And you didn't escape out the +
.
Actually, between the T
and :
in your regex, put (\d\d)
:
/^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)\.(\d{3})\+(\d\d):(\d\d)$/
/^\d{4}\-\d{2}\-\d{2}T\d{2}\:\d{2}\:\d{2}\.\d{3}\+\d{2}\:\d{2}$/
精彩评论