SyntaxLength
SyntaxLength["string"] finds the number of characters starting at the beginning of a string that correspond to syntactically correct input for a single Wolfram Language expression.
Examples
Find the syntax length of a string:
SyntaxLength["1+2 3+4"]
(* 3 *)Please visit the official Wolfram Language Reference for more details.