Regex Constrains within the attributes of entities and relations

Hi all, according to the documentation, regex constraints can be applied within the owning definition of entities and relations.

Documentation Example:

define
full-name sub attribute, value string;
office-location sub attribute, value string;
id sub attribute, value string;
email sub id;
employee-id sub id;
user sub entity,
    owns full-name,
    owns email @unique, regex "^(.+)@(\\S+)$";
employee sub user,
    owns employee-id @key,
    owns office-location, regex "^(London|Paris|Dublin)$";

However, when I execute this define query:

define product sub entity, owns price, regex "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z]{2,}$", owns size, owns identifier @key, plays selling:sold;

I get this error:

[TYR01] Invalid Type Read: Invalid concept conversion from 'product' to 'AttributeType'.

which I interpret as “Regex constraints should be within the attribute definition” but maybe I just have an error in my define query?

I would highly appreciate your help! :slight_smile:

1 Like

Hi, the error is correctly thrown and your assumption as to its nature is also correct. The regex constraint should be placed directly on the attributes as a statement, for example:

office-location regex "^(London|Paris|Dublin)$";

It applies to all instances of the attribute type, regardless of the type of the owner.

Could you please let us know where you found that example? We’ll make sure to correct it.

1 Like

Hi @jameswhiteside ,

Thanks for your answer. Makes also very much sense to define it globally for the attribute as such.

I found the example here under “Attribute Constraints”

1 Like