Consider this example:
expr = a (1 + b + c d + Sqrt[-2 d e + fg + h^2] + a j );
Now I’d like to insert a complex I before the term in the square root and retain the rest of the expression. I know that expr has only one Sqrt term in it. So I tried the following:
ToBoxes@# /. SqrtBox@x_ :> RowBox[{I, " ", SqrtBox@x}] &[
expr] // ToExpression
Out[1] = $Failed
Q1: Why does it fail?
The workaround was to use a different variable and then replace it with I as so:
(ToBoxes@# /. SqrtBox@x_ :> RowBox[{k, " ", SqrtBox@x}] &[expr] //
ToExpression) /. k -> I

Q2: Why does this work?
Q3: Are there alternate/better ways to do this?
The parts of a box expression that aren’t structural need to be strings. So you want