Use this:
var temp = "Model transfer transfer transfer transfertransfer";
var count = (temp.match(/transfer/ig) || []).length;
let abc;
if (count > 1) {
abc = temp.replace(/[s]*transfer[s]*/ig, '').concat(` transfer ${count}`);
}
console.log(count);
console.log(abc)
This way you are replacing all "transfer" string with additional whitespaces. Mind the g
flag in the replace regex as otherwise Javascript will only replace the first occurrence.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…