开发者

regular expressions for timestamps

开发者 https://www.devze.com 2023-04-11 11:24 出处:网络
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

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}$/
0

精彩评论

暂无评论...
验证码 换一张
取 消