let imageName = 'cbtmmprice'
let userID = 't03'
let matchReg = '^' + imageName + '-' + userID.toLowerCase() + '(-\\d+)?\\b'
let maxNum = 0
let newInstanceID = `${imageName}-${userID}`
const f1 = function(rsData){
for(let elem of rsData) {
let x = elem.InstanceID.match(matchReg)
console.log(x)
//不为null,即符合正则匹配
if (x !== null) {
//策略实例格式:`${imageName}-${cdata.UserID}`+数字序号
if (x[1] !== undefined) {
let tempNum = Number(x[1].slice(1))
maxNum = Math.max(maxNum, tempNum)
//策略实例格式:`${selectImageName}-${cdata.UserID}`
newInstanceID = `${imageName}-${userID}-${maxNum + 1}`
}
}
}
}
let rsData=[{InstanceID:'cbtmmprice-t03'}]
f1(rsData)
console.log(newInstanceID)
console