({{, (RefLink[SyntaxQ, paclet:ref/SyntaxQ])["string"]
returns (RefLink[True, paclet:ref/True]) if the string corresponds to syntactically correct input for a single Wolfram Language expression, and returns (RefLink[False, paclet:ref/False]) otherwise. }, {, (RefLink[SyntaxQ, paclet:ref/SyntaxQ])["string",form]
uses interpretation rules corresponding to the specified form.}})

OpenersNotesSection(Spacer1)Details

If (RefLink[SyntaxQ, paclet:ref/SyntaxQ]) returns (RefLink[False, paclet:ref/False]), you can find the position of a syntax error using (RefLink[SyntaxLength, paclet:ref/SyntaxLength]).

form can be (RefLink[InputForm, paclet:ref/InputForm]), (RefLink[StandardForm, paclet:ref/StandardForm]), (RefLink[TeXForm, paclet:ref/TeXForm]), (RefLink[TraditionalForm, paclet:ref/TraditionalForm]), or (RefLink[MathMLForm, paclet:ref/MathMLForm]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (6)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Test if a string is valid Wolfram Language syntax:

SyntaxQ["a[b[c,1],2],3]"]

SyntaxQ["a[b[c,1],2]"]

When (RefLink[SyntaxQ, paclet:ref/SyntaxQ]) gives (RefLink[True, paclet:ref/True]), the string can be converted to an expression:

ToExpression["a[b[c,1],2]"]

Request input from a dialog repeatedly until it is syntactically correct:

While[!SyntaxQ[input=InputString["Please enter a Mathematica expression"]],Print[input," is not valid Mathematica syntax."]];ToExpression[input]

OpenersExampleSection1(Spacer1)Scope  (2)

Verify a (RefLink[TeXForm, paclet:ref/TeXForm]) input:

SyntaxQ["x+\\frac{1}{2}",TeXForm]

This can be converted to a Wolfram Language expression:

ToExpression["x+\\frac{1}{2}",TeXForm]

(RefLink[SyntaxQ, paclet:ref/SyntaxQ]) can verify strings containing (RefLink[StandardForm, paclet:ref/StandardForm]) or (RefLink[TraditionalForm, paclet:ref/TraditionalForm]) boxes:

SyntaxQ[ToString[(x^2)+(y^2),StandardForm]]

It does not accept the boxes themselves:

SyntaxQ[ToBoxes[(x^2)+(y^2),StandardForm]]

OpenersExampleSection2(Spacer1)Properties & Relations  (2)

The default interpretation form is (RefLink[InputForm, paclet:ref/InputForm]):

SyntaxQ["<math><mfrac><mi>&#960;</mi><mn>4</mn></mfrac></math>"]

SyntaxQ["<math><mfrac><mi>&#960;</mi><mn>4</mn></mfrac></math>",InputForm]

This input is valid (RefLink[MathMLForm, paclet:ref/MathMLForm]):

SyntaxQ["<math><mfrac><mi>&#960;</mi><mn>4</mn></mfrac></math>",MathMLForm]

Use (RefLink[SyntaxLength, paclet:ref/SyntaxLength]) to find the longest leading substring which is syntactically valid:

SyntaxQ["Sin]x["]

SyntaxLength["Sin]x["]

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

({{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])}, {▪(RefLinkPlain[Testing Expressions, paclet:guide/TestingExpressions])}})}})