I have a json object
const item = {
fooUrl : 'www.google.com',
fooDomain : 'www.yahoo.com'
}
and an input string foo$ENV[fooDomain]bar
. I want to replace the $ENV[fooDomain]
with item.fooDomain
and similarly for accountsUrl
,
I want this to happen dynamically meaning even if a new unknown key is added the pattern should find and replace $ENV[something]
value.
What I have done till now
console.log(str.replace(/(?:^|\s)$ENV[(\w*)](.*?)(?:\s|$)/g,item.accountsUrl // how to make this dynamic ?));