I'm getting strings with values such as /Date(1)/
and /Date(-99999)/
. The digits are variable length.
Wouldn't the regex just be this: ^/Date\(d+\)/$
I'm getting strings with values such as /Date(1)/
and /Date(-99999)/
. The digits are variable length.
Wouldn't the regex just be this: ^/Date\(d+\)/$
No, your regular expression is missing the optional minus in front of the digits (\d
). You also need to escape the /
as these are also the delimiter for regular expressions. Try this regular expression:
^/Date\(-?\d+\)/$
Either within the RegExp constructor:
new RegExp("^/Date\\(-?\\d+\\)/$")
Or as literal:
/^\/Date\(-?\d+\)\/$
Not quite. You're not allowing for the possibility of a leading hyphen, and your slashes are a little wonky.
/^Date\(-?\d+\)$/
Seems that you are getting JSON Date values serialized by ASP .NET, the slashes are included on the strings, to capture the timestamp you can simply match the optional minus sign and any digit character sequence:
var date = "\/Date(1240718400000)\/";
var timeStamp = date.match(/-?\d+/)[0]; // 1240718400000;
Or a more restrictive one:
var timeStamp = date.match(/\/Date\((-?\d+)\)\//)[1];