There is a line:
let formula = 'A+B*(ABS(BA))' And there is an object:
let replace_func = { A: 'C+5', B: 'D-2' } It is necessary to replace the variables in the string 'formula' with the elements 'replace_func' according to the keys, so that it turns out:
let result = '(C+5)+(D-2)*(ABS((D-2)-(C+5)))' To avoid replacing the ABS () function in the name, it was decided to use the regular schedule:
let replace_regx = new RegExp('[\/\*\-\+\(]?' + cur_key + '[\/\*\-\+\)]?') formula = formula.replace(replace_regx, replace_func[cur_key]) But on the regular schedule, not only the name of the variable is replaced, but also the signs before and after it (eg. Instead of 'A' is taken as '-A)' )
How can I solve this problem? In regulars is not strong, so I ask for help)