One approach that may be familiar to more experienced users is based on the input syntax described in String Representation of Boxes.
\(input\) raw boxes
This appears to work but closer inspection shows that it is not exact:
"\({1*^4, 000123, a*b c}\)" // ToExpression
RowBox[{"{",RowBox[{"1*^4",",","000123",",",RowBox[{"a","*","b","c"}]}],"}"}]
RowBox[{"{",RowBox[{"1*^4",",","000123",",",RowBox[{"a","*","b"," ","c"}]}],"}"}]
(Copy & paste from Show Expression on the lower line.)
Greater changes are apparent in the invalid-expression example:
"\(0001+`1,*^6*a b\)" // ToExpression
RowBox[{RowBox[{"0001","+",RowBox[{"`","1"}]}],",",RowBox[{"*",RowBox[{"^","6"}],"*","a","b"}]}]
RowBox[{RowBox[{"0001","+","`1"}],",",RowBox[{"*",RowBox[{"^","6"}],"*","a"," ","b"}]}]
The other approach I know it to use $PreRead
to capture the Box form input:
$PreRead = # /. {
RowBox[{"raw", "[", raw__, "]"}] |
RowBox[{raw__, "//", "raw"}] |
RowBox[{"raw", "@", raw__}] :>
ToString[Unevaluated[raw], StandardForm]
} &;
Output still does not precisely match the Show Expression form but it is close:
raw[0001+`1,*^6*a b]
RowBox[{RowBox[{"0001","+","`1"}],",",RowBox[{"*",RowBox[{"^","6"}],"*","a","b"}]}]
RowBox[{RowBox[{"0001","+","`1"}],",",RowBox[{"*",RowBox[{"^","6"}],"*","a"," ","b"}]}]
The discrepancy actually ends up being advantageous as this is the form that is seen by CellEvaluationFunction
and that was my original intent.
It is also more convenient than having to wrap input in ToExpression["\( \)"]
.
I wonder if there is not a FrontEnd function that already does this.