how to remove everything except {Group} and {Desc} from string variable cardLabel and add a space between them 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}';
If I understand this correctly, you are sending values from a server to a client App or WebApp. You are facing this kind of issue because you are not sending it with a standard format like JSON or XML. Encode your data in JSON on the server and send that JSON. Then depending the frontend project, you can check if the (group, desc, termMonth, Month etc) keys exists and render them accordingly. For clarity, what is the frontend and backend language?
I get the values from the server which I can't change. I run an API end point and get the data. Please note my desire end result should be one of the following: cardLabel='{Group} {Desc}'; cardLabel='{Desc} {Group}'; frontEnd is Angular, Backend is C#