({{, (RefLink[SyntaxLength, paclet:ref/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. }})

OpenersNotesSection(Spacer1)Details

(RefLink[SyntaxLength, paclet:ref/SyntaxLength]) effectively returns the position of a syntax error, if one exists.

If (RefLink[SyntaxLength, paclet:ref/SyntaxLength]) returns a position past the end of the string, it indicates that the string is syntactically correct as far as it goes, but needs to be continued in order to correspond to input for a complete Wolfram Language expression.

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Give the length of the syntactically correct beginning substring:

SyntaxLength["a[1]] + b[2]"]

The syntactically correct part can be converted to an expression:

ToExpression[StringTake["a[1]] + b[2]",%]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[SyntaxQ, paclet:ref/SyntaxQ])  ▪  (RefLink[$SyntaxHandler, paclet:ref/$SyntaxHandler])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Converting between Strings, Boxes, and Expressions, paclet:tutorial/ConvertingBetweenStringsBoxesAndExpressions])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Converting between Expressions & Strings, paclet:guide/ConvertingBetweenExpressionsAndStrings])}})}})