I am writing a string parser that takes input like "{x} + 20" and evaluates the lexical value of x with the sum of 20 and returns. So
var x = 10;
var new = eval("{x} + 20".replace("/\{(\w+\}/g", "$1"));
and here "new" should equal 30.
How can this be done?