regex
|
This documentation is not current - it is for TypeDB 2.x, which is no longer supported. View the documentation for TypeDB 3.x: |
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
regexkeyword -
Object — a regular expression to set possible values
<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
visibility sub attribute, value string, regex "^(public|private|closed)$";