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:

Introduced in 1991
 (2.0)
 |
Updated in 2017
 (11.1)