Anirban Sen Chowdhary Anirban Sen Chowdhary - 3 years ago 221
Java Question

Need a regex expression to validate timestamp with utc

I have a date format like :-

2014-08-17T14:07:30+0521
or
2015-05-21T14:07:30+0521


Now I want to have a regex expression that can validate this date format..

I tried with the following format as given here How to check an UTC formatted date with a regular expression? :-

\d{4}-[0-1]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-6]\d:\d{3}\+\d\d:\d\d


but couldn't succeed ..
Since I am very new to this regex expression, I am finding it difficult to construct the expression that could validate successfully the above timestamp format with utc

Please note that, I want regex expression, other solution option will not work for me

Thanks

Answer Source

You can use the following (the one you are using has different matching at the end):

\d{4}-[0-1]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\+\d{4}

Edit: In Java you can use the following:

\\d{4}-[0-1]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\+\\d{4}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download