I need to pick specific words from string. Words are dynamic.
const KEY_VAL_MAP = { car: vehicle };
const KEY = 'car';
let sampleString = 'hey this i need to replace car ${car}';
sampleString = sampleString.replace(new RegExp(`\\b(?:${KEY})\\b`, 'g'), KEY_VAL_MAP[_key]);
the result expected is : 'hey this i need to replace vehicle ${car}';
With the above regex it will replace every car
with vehicle
. What needs to be updated in regex so that everything in string under ${}
is excluded.