Officially out now: The TypeDB 3.0 Roadmap

regex

The regex keyword is used in TypeQL schema to define the regular expression to restrict possible values for attributes of a given type.

Syntax

The syntax of a regex statement includes:

  • Subject — attribute type label

  • Predicate — the regex keyword

  • Object — a regular expression to set possible values

Syntax
<attribute-type> regex <regular-expression>;

Behavior

TypeQL statements with the regex keyword can be used only in Define queries.

The regex keyword adds a constraint on values of attributes of a given attribute type to be valid strings according to the object regular expression.

Usage in a schema definition

For this example, use a database with the IAM schema and sample data loaded.

Since in Define queries you can’t use variables, the subject of a regex statement can only be an attribute type label.

For example, to define a new attribute type visibility with a value type of string, and values to be limited to public, private, or closed, use:

Define query regex example
define
visibility sub attribute, value string, regex "^(public|private|closed)$";

Learn more

Learn more about type statement in TypeQL.

Learn about types in TypeQL.