const str = 'scsi15';
const words = str.split(/[0-15]*$/);
Code output: Array ["scsi", ""]
,
However, this is the output I want: Array ["scsi", "15"]
const str = 'scsi15';
const words = str.split(/[0-15]*$/);
Code output: Array ["scsi", ""]
,
However, this is the output I want: Array ["scsi", "15"]
You could match by non digits or digits.
const
str = 'scsi15',
words = str.match(/\D+|\d+/g);
console.log(words);
You can destruct regex capturing groups if the order is always the same
const str = 'scsi15';
const re = /(\D*)(\d*)/;
const [_, word, num] = re.exec(str); // _, is first item. Could be just ,
console.log(word, num)