Js regular substitution

let k1 = kpi1 + kpi2 + (kpi3 - kpi4) * kpi5;   => {kpi1:1,kpi2:12,kpi3:2,kpi4:23,kpi5:78}
let k2 = kpi1 - (kpi2 * kpi3);            => {kpi1:1,kpi2:12,kpi3:2,}
let k3 = kpi1 * kpi2 / kpi3;    => {kpi1:1,kpi2:12,kpi3:2}
:kpi,
Jun.29,2021

clipboard.png
is this what you want?


come out with a regular match

const k1 = 'kpi1 + kpi2 + (kpi3 - kpi4) * kpi5';
const obj = {kpi1:1,kpi2:12,kpi3:2,kpi4:23,kpi5:78};
let k2 = k1.replace(/kpi[0-9]+/g,function(){
  return obj[arguments[0]]
})
console.log(k2) // '1 + 12 + (2 - 23) * 78'

console.log(eval(k2)) // -1625
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b362c6-2b53d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b362c6-2b53d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?