Get Split Number And String From String
I have an array of string like below: var array =[]; array.push('Complex12'); array.push('NumberCar1'); array.push('Protect5'); I want to split the string and number of each item.
Solution 1:
I think you just missed +
in first regexp
var Id = parseInt(array[0].match(/\d+/g));
Solution 2:
Do it in one pattern with capture groups:
var mystr = "Complex12";
if (m = mystr.match(/^([a-z]+)([0-9]+)$/i)) {
var type = m[1];
var id = m[2];
}
Post a Comment for "Get Split Number And String From String"