> ## 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 ソース

> 正規表現ツリー辞書のソースとして YAML ファイルを設定します。

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>;
};

`YAMLRegExpTree` ソースは、ローカルファイルシステム上の YAML ファイルから正規表現ツリーを読み込みます。
これは [`regexp_tree`](/ja/reference/statements/create/dictionary/layouts/regexp-tree) 辞書レイアウト専用に設計されており、
ユーザーエージェントのパースなど、パターンベースのルックアップ向けに、正規表現から属性への階層的なマッピングを提供します。

<Note>
  `YAMLRegExpTree` ソースは ClickHouse Open Source でのみ利用できます。
  ClickHouse Cloud では、代わりに辞書を CSV にエクスポートし、[ClickHouse table source](/ja/reference/statements/create/dictionary/sources/clickhouse) を使用して読み込んでください。
  詳細は [Using regexp\_tree Dictionaries in ClickHouse Cloud](/ja/reference/statements/create/dictionary/layouts/regexp-tree#use-regular-expression-tree-dictionary-in-clickhouse-cloud) を参照してください。
</Note>

<div id="configuration">
  ## 設定
</div>

```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);
```

設定フィールド:

| 設定     | 説明                                                                             |
| ------ | ------------------------------------------------------------------------------ |
| `PATH` | 正規表現ツリーを含む YAML ファイルへの絶対パスです。DDL で作成する場合、ファイルは `user_files` ディレクトリ内になければなりません。 |

<div id="yaml-file-structure">
  ## YAML ファイルの構造
</div>

YAML ファイルには、正規表現ツリーのノードの一覧が含まれます。各ノードは属性と子ノードを持つことができ、階層構造を形成します。

```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'
```

各ノードは次の構造になっています。

* **`regexp`**: このノードの正規表現。
* **attributes**: ユーザー定義のDictionary 属性 (例: `name`、`version`) 。属性値には、`\1` または `$1` (1～9の数字) で表される、正規表現のキャプチャグループへの**後方参照**を含めることができます。これらはクエリ時に、マッチしたキャプチャグループに置き換えられます。
* **child nodes**: 子ノードのリストです。各子ノードはそれぞれ独自の属性を持ち、必要に応じてさらに子ノードを持つこともできます。子ノードのリスト名は任意です (例: 上記の `versions`) 。文字列のマッチングは深さ優先で行われます。文字列がノードに一致した場合は、その子ノードもチェックされます。最も深い階層で一致したノードの属性が優先され、同名の親属性を上書きします。

<div id="related-pages">
  ## 関連ページ
</div>

* [regexp\_tree Dictionary レイアウト](/ja/reference/statements/create/dictionary/layouts/regexp-tree) — レイアウト設定、クエリ例、マッチングモード
* [dictGet](/ja/reference/functions/regular-functions/ext-dict-functions#dictGet), [dictGetAll](/ja/reference/functions/regular-functions/ext-dict-functions#dictGetAll) — regexp tree Dictionaries をクエリする関数
