As you know the format is like:
"YYYY-MM-DDTHH:NN:SS.ZZZ+XX:XX" (i.e. "2009-03-24T16:24:32.057+01:00")
I have to do it in a ActionScript3 class but any source will be appreciated, thanks.
As you know the format is like:
"YYYY-MM-DDTHH:NN:SS.ZZZ+XX:XX" (i.e. "2009-03-24T16:24:32.057+01:00")
I have to do it in a ActionScript3 class but any source will be appreciated, thanks.
\d{4}-[0-1]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-6]\d.\d{3}\+\d\d:\d\d
Or something similar?
More checks of the valid range are probably better done after the reg.ex.
Regex should be something like this:
\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}\+\d{2}:\d{2}
At the risk of being down-voted, I'd like to suggest that you don't do range-checking operations with a regex. When you find yourself having to deal with fixed format strings, it's usually easier to use string extraction (substring) from the known positions and converting relevant fields to integers for range checking.
Hence, for something like 2009-03-24T16:24:32.057+01:00
:
Now I may have gotten some of the values wrong there, I haven't checked thoroughly, but I believe that sort of code, properly documented, is more understandable than a regex that has numeric range contortions.
By all means use a regex to check that numerics and separators are in the right places, but please don't use it for things like checking that a number is between 00 and 23.
A regex that should work on just about any engine would be:
[0-9]{4}-[0-9]{2}-[0-9]{2}
T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}
+[0-9]{2}:[0-9]{2}
escaping the "-"
and "+"
characters if necessary, although you may have to use [0-9][0-9]
instead of [0-9]{2}
on the more simplistic engines.
Have a look at this related question:
Actionscript 3 - Fastest way to parse yyyy-mm-dd hh:mm:ss to a Date object?
The accepted answer provides a way to parse an UTC time string to a Date
object.