# Regex constraints in abstract attributes

**URL:** <https://forum.typedb.com/t/regex-constraints-in-abstract-attributes/578>\
**Category:** TypeQL\
**Created:** [19 September 2024 18:28 UTC](https://forum.typedb.com/t/regex-constraints-in-abstract-attributes/578 "2024-09-19T18:28:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zelit](https://avatars.discourse-cdn.com/v4/letter/z/65b543/32.png) [@zelit](https://forum.typedb.com/u/zelit)\
**Post date:** [19 September 2024 18:28 UTC](https://forum.typedb.com/t/regex-constraints-in-abstract-attributes/578/1 "2024-09-19T18:28:15Z")

</div>

Hello,

Consider the query

```auto
insert
$r isa resource, has hex "00t";

```

This query is correctly validated (and the data not inserted) in the schema

```auto
define
hex sub attribute, value string,
   regex "^([0-9a-f]{2})+$";

resource sub entity,
   owns hex;

```

However, an analogous query with invalid hex values succeeds in the following schema

```auto
define
hex sub attribute, value string, abstract,
   regex "^([0-9a-f]{2})+$";

checksum sub hex;
address sub hex;

resource sub entity,
   owns checksum,
   owns address;

```

This suggests that `regex` constraints defined for abstract attributes are ignored by its subtypes.

1. Is this the expected behavior?
2. In that case, out of curiosity, could you please roughly elaborate on the reasons for such a decision?

I think that the second model would be useful, e.g., to define a “data type” (such as hex) as a super type of several attributes in a large schema. The alternative seems to be defining the regex for each subtype.

```auto
define
hex sub attribute, value string, abstract;

checksum sub hex, regex "^([0-9a-f]{2})+$";
address sub hex, regex "^([0-9a-f]{2})+$";
...

```

Thanks in advance

---

<div class="post-metadata">

**Author:** ![krishnan](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/krishnan/32/36_2.png) [@krishnan](https://forum.typedb.com/u/krishnan)\
**Post date:** [23 September 2024 12:41 UTC](https://forum.typedb.com/t/regex-constraints-in-abstract-attributes/578/2 "2024-09-23T12:41:18Z")

</div>

> [@zelit](#):
>
> 1. Is this the expected behavior?

No.

It works as you’d expect in 3.0. Is it important to you that we fix it in a 2.x release? Or can you workaround it till 3.0 GA by declaring the regex on each of the subtypes?

---

<div class="post-metadata">

**Author:** ![zelit](https://avatars.discourse-cdn.com/v4/letter/z/65b543/32.png) [@zelit](https://forum.typedb.com/u/zelit)\
**Post date:** [23 September 2024 15:19 UTC](https://forum.typedb.com/t/regex-constraints-in-abstract-attributes/578/3 "2024-09-23T15:19:34Z")

</div>

I can happily wait for the fix in v3.0. I have an alternative schema based on the features on the roadmap, so I will keep the compact version above for when v3.0 sees the light.

Thanks for the nice work over there :).
