> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# YAMLRegExpTree dictionary source

> Configure a YAML file as a source for regular expression tree dictionaries.

export const CloudNotSupportedBadge = () => {
  return <div className="cloudNotSupportedBadge">
            <div className="cloudNotSupportedIcon">
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path strokeWidth="1.5" d="M6.33366 12.6666L12.3739 12.6667C13.6593 12.6667 14.7073 11.6187 14.7073 10.3334C14.7073 9.04804 13.6593 8.00003 12.3739 8.00003C12.3739 8.00003 12.3337 7.66659 12.0003 7.33325M10.667 5.33322C8.00033 2.33325 4.45395 4.78537 4.14195 6.68203C2.55728 6.7627 1.29395 8.06203 1.29395 9.6667C1.29395 11.3234 2.66699 12.6666 4.00033 12.6666" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path strokeWidth="1.5" d="M2.66699 14L12.0003 4.66663" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
            </svg>

        </div>
            Not supported in ClickHouse Cloud
        </div>;
};

The `YAMLRegExpTree` source loads a regular expression tree from a YAML file on the local filesystem.
It is designed exclusively for use with the [`regexp_tree`](/reference/statements/create/dictionary/layouts/regexp-tree) dictionary layout
and provides hierarchical regex-to-attribute mappings for pattern-based lookups such as user agent parsing.

<Note>
  The `YAMLRegExpTree` source is only available in ClickHouse Open Source.
  For ClickHouse Cloud, export the dictionary to CSV and load it via a [ClickHouse table source](/reference/statements/create/dictionary/sources/clickhouse) instead.
  See [Using regexp\_tree dictionaries in ClickHouse Cloud](/reference/statements/create/dictionary/layouts/regexp-tree#use-regular-expression-tree-dictionary-in-clickhouse-cloud) for details.
</Note>

<h2 id="configuration">
  Configuration
</h2>

```sql theme={null}
CREATE DICTIONARY regexp_dict
(
    regexp String,
    name String,
    version String
)
PRIMARY KEY(regexp)
SOURCE(YAMLRegExpTree(PATH '/var/lib/clickhouse/user_files/regexp_tree.yaml'))
LAYOUT(regexp_tree)
LIFETIME(0);
```

Setting fields:

| Setting | Description                                                                                                                                      |
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `PATH`  | The absolute path to the YAML file containing the regular expression tree. When created via DDL, the file must be in the `user_files` directory. |

<h2 id="yaml-file-structure">
  YAML file structure
</h2>

The YAML file contains a list of regular expression tree nodes. Each node can have attributes and child nodes, forming a hierarchy:

```yaml theme={null}
- regexp: 'Linux/(\d+[\.\d]*).+tlinux'
  name: 'TencentOS'
  version: '\1'

- regexp: '\d+/tclwebkit(?:\d+[\.\d]*)'
  name: 'Android'
  versions:
    - regexp: '33/tclwebkit'
      version: '13'
    - regexp: '3[12]/tclwebkit'
      version: '12'
    - regexp: '30/tclwebkit'
      version: '11'
    - regexp: '29/tclwebkit'
      version: '10'
```

Each node has the following structure:

* **`regexp`**: The regular expression for this node.
* **attributes**: User-defined dictionary attributes (e.g. `name`, `version`). Attribute values may contain **back references** to capture groups in the regular expression, written as `\1` or `$1` (numbers 1-9). These are replaced with the matched capture group at query time.
* **child nodes**: A list of children, each with its own attributes and optionally more children. The name of the child list is arbitrary (e.g. `versions` above). String matching proceeds depth-first: if a string matches a node, its children are also checked. Attributes of the deepest matching node take precedence, overriding equally named parent attributes.

<h2 id="related-pages">
  Related pages
</h2>

* [regexp\_tree dictionary layout](/reference/statements/create/dictionary/layouts/regexp-tree) — layout configuration, query examples, and matching modes
* [dictGet](/reference/functions/regular-functions/ext-dict-functions#dictGet), [dictGetAll](/reference/functions/regular-functions/ext-dict-functions#dictGetAll) — functions for querying regexp tree dictionaries
