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 , "/");
This gets me to 2016/03, but how can i get to 03/16?
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 , "/");
This gets me to 2016/03, but how can i get to 03/16?
one solution without regex:
Do you really need to use RegExp?
Why not creating a simple function that splits the exp Date and returns it the way you want it?
The split functions creates an array, the element in position
1
is the month, the element in position2
is the year, on the latter you apply the substring function which extrapolates the last two digits.With a RegExp :
'2016-03'.replace(/^\d{2}(\d{2})-(\d{2})$/, '$1/$2')