I have the following string which I ultimately need to have in the format of mm/yy
var expDate = 2016-03; var formatExp = expDate.replace(/-/g , \"/\
one solution without regex:
var expDate = '2016-03'; var formatExp = expDate.split('-').reverse().join('/'); //result is 03/2016 alert('result: ' + formatExp); var formatExpShort = expDate.substring(2).split('-').reverse().join('/'); //result is 03/16 alert('result short: ' + formatExpShort);