SyntaxQ

SyntaxQ["string"]

returns True if the string corresponds to syntactically correct input for a single Wolfram Language expression, and returns False otherwise.

SyntaxQ["string",form]

uses interpretation rules corresponding to the specified form.

Details

Examples

open allclose all

Basic Examples  (2)

Test if a string is valid Wolfram Language syntax:

When SyntaxQ gives True, the string can be converted to an expression:

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

Scope  (2)

Verify a TeXForm input:

This can be converted to a Wolfram Language expression:

SyntaxQ can verify strings containing StandardForm or TraditionalForm boxes:

It does not accept the boxes themselves:

Properties & Relations  (2)

The default interpretation form is InputForm:

This input is valid MathMLForm:

Use SyntaxLength to find the longest leading substring which is syntactically valid:

Wolfram Research (1991), SyntaxQ, Wolfram Language function, https://reference.wolfram.com/language/ref/SyntaxQ.html (updated 2017).

Text

Wolfram Research (1991), SyntaxQ, Wolfram Language function, https://reference.wolfram.com/language/ref/SyntaxQ.html (updated 2017).

CMS

Wolfram Language. 1991. "SyntaxQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2017. https://reference.wolfram.com/language/ref/SyntaxQ.html.

APA

Wolfram Language. (1991). SyntaxQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SyntaxQ.html

BibTeX

@misc{reference.wolfram_2023_syntaxq, author="Wolfram Research", title="{SyntaxQ}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/SyntaxQ.html}", note=[Accessed: 18-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_syntaxq, organization={Wolfram Research}, title={SyntaxQ}, year={2017}, url={https://reference.wolfram.com/language/ref/SyntaxQ.html}, note=[Accessed: 18-March-2024 ]}