New to regex.
Need regular expression to match strings like T17:44:24Z
from parent strings like 2015-12-22T17:44:24Z
using javascript regex.
Once match is found will replace it with null or empty space.
To be specific i am trying to remove the time stamp from date string and obtain only date part.
Please help me in this
New to regex.
Need regular expression to match strings like T17:44:24Z
from parent strings like 2015-12-22T17:44:24Z
using javascript regex.
Once match is found will replace it with null or empty space.
To be specific i am trying to remove the time stamp from date string and obtain only date part.
Please help me in this
Share Improve this question asked Dec 23, 2015 at 12:25 KrankyCodeKrankyCode 4511 gold badge8 silver badges25 bronze badges 1-
1
Replace
/T\d{2}:\d{2}:\d{2}Z/
with empty string. – ndnenkov Commented Dec 23, 2015 at 12:26
2 Answers
Reset to default 2You can use a simple regex like this:
T\d{2}:\d{2}:\d{2}Z
or
T(?:\d{2}:){2}\d{2}Z
Working demo
In case your T
and Z
are dynamic the, you can use:
[A-Z]\d{2}:\d{2}:\d{2}[A-Z]
Code
var re = /T\d{2}:\d{2}:\d{2}Z/g;
var str = '2015-12-22T17:44:24Z';
var subst = '';
var result = str.replace(re, subst);
You don't need regex on this. You just split the string by T
and get the second element from array, which would be 17:44:24Z
in your case.
var date = '2015-12-22T17:44:24Z';
var result = date.split('T')[1];
If you also want to preserve T, you can just prepend it to the result:
var result = 'T' + date.split('T')[1]
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745600278a4635360.html
评论列表(0条)