I have a duration string \"PT1M33S\". I would like to get result in the following format -> 01:33 Can anyone please tell me how to do so using js or jquery??
You can match the digits and pad them to format-
var string= "PT1M33S", array=string.match(/(\d+)(?=[MHS])/ig)||[]; var formatted=array.map(function(item){ if(item.length<2) return '0'+item; return item; }).join(':'); formatted
/* returned value: (String) 01:33 */