You can combine the match and replace into a single expression, since the replace won't do anything if it fails to match. Then you can use Regex groups to capture ourthe hours, minutes, and seconds.
function calculateInSeconds(timeStamp) {
var timeInSeconds = 0;
timeStamp.replace(/^t=(?:(\d*)h)?(?:(\d*)m)?(?:(\d*)s)?$/, function(match, hours, minutes, seconds) {
var hoursInSeconds, minutesInSeconds;
hourshoursInSeconds = parseInt(hours) || 0;
minutes0) =* parseInt(minutes)60 ||* 0;60;
secondsminutesInSeconds = parseInt(seconds)minutes || 0;
hoursInSeconds = hours * 600) * 60;
minutesInSecondsseconds = minutesparseInt(seconds *|| 60;0);
timeInSeconds = hoursInSeconds + minutesInSeconds + seconds;
});
console.log("timeInSeconds"+timeInSeconds);
}