how to remove everything except {Group} and {Desc} from string variable cardLabel and add a space between {Group} and {Desc} in javascript?
I get cardLabel value from database and the value sometimes contain all 6 variables but can contain value with sometimes just 2 variables, sometimes with sometimes just 4 variables. Please note order for the variables can be different and can contain more variables in future.
cardLabel’s dynamic value examples:
cardLabel='{Group} {Desc} – {termMonth} Month – {termOdometer} KMs/Miles {DeductibleAmount} {DeductibleType}’;
cardLabel='{Desc} – {termMonth} Month – {termOdometer} KMs/Miles’;
cardLabel='{Desc} {Group} – {termMonth} Month’;
cardLabel='{Group} {Desc} – {termMonth} Month {DeductibleAmount}’;
I have tried the following code but it is not ideal because the database value can contain more variables in future:
`cardLabel = cardLabel.replace(‘{termMonth}’,”).replace(‘{termOdometer}’,”).replace(‘{DeductibleAmount}’,”).replace(‘{DeductibleType}’,”).replace(‘-‘, ”);
The desire end result should be one of the following:
cardLabel='{Group} {Desc}’;
cardLabel='{Desc} {Group}’;