How do I replace content inside a Held expression without local values coming through?
For example if you run the following code you get g[2] instead of g[x](the intended form).
x = 2;
Replace[HoldComplete[g["x"]], {
y_String :> With[{
eval = Symbol[y]},
eval /; True]
}, {0, Infinity}]
The following questions are related
EDIT: Although rm-rf's trick is clever it partially works. His current code adds an additional defer to the current code.
InputForm@HoldComplete[g["x"]] /.
s_String :> With[{x = ToExpression[s, InputForm, Defer]}, x /; True]
returns HoldComplete[g[Defer[x]]] instead of HoldComplete[g[x]]. Ultimately you could strip out the Defers which is likely what I will end up doing.