I have a use case where I have a string with the same substring if followed continuously should return the string and count together. If not, it should return the same string. We need to check for only one value here, in the below use case it is 'transfer'. Should be case insensitive. I do not care if the string 'Name' occurs more than once.
Example:
String is 'Name transfer transfer transfer transfertranfser' should return 'Name transfer 5' as 5 is the length of transfer. String is 'Name transfer Transfer transfer TransferTranfser' should return 'Name transfer 5' as 5 is the length of transfer. String is 'Name transfer name transfer' should return 'Name transfer name transfer' as transfer is not continous.
Please advice.
var temp = "Model transfer transfer transfer transfertransfer";
var count = (temp.match(/transfer/g) || []).length;
let abc;
if (count > 1) {
abc = temp.replace('transfer', `transfer ${count}`)
}
console.log(count);
console.log(abc)
How do I remove the end of the string? Please advice. Any help is appreciated.