# 常见问题

### 快速检索⬇️

[**为什么要使用正则？**](#wei-shen-me-yao-shi-yong-zheng-ze)

[**工具模式和通用模式的区别？**](#gong-ju-mo-shi-he-tong-yong-mo-shi-de-qu-bie)

[**如何教会AI输出？**](#ru-he-jiao-hui-ai-shu-chu)

[**原来的代码如何改成正则？**](#yuan-lai-de-dai-ma-ru-he-gai-cheng-zheng-ze)

[**AI输出总是不稳定？**](#ai-shu-chu-zheng-ze-zong-shi-bu-wen-ding)

***

#### 为什么要使用正则？

* 正则是一个，让AI角色卡有更多交互的解决方案。
* 使用正则最直观的提升就是，代码不再占用AI输出，人设输入的token了。
* 这意味着，
  * 有更多的token可以用于完善人设
  * AI聊天过程中记忆会更好，输出速度更快
  * 解决了爆代码问题
  * 你可以为角色卡写丰富有趣的交互，token不再限制你的创作

如下方的例子

AI只需要输出：

<figure><img src="https://cdn.mufy.ai/images/d3864fad-a7ca-48e8-33a5-7ede11cd7c00/public" alt=""><figcaption></figcaption></figure>

就可以实现：

<figure><img src="https://cdn.mufy.ai/images/8eadde06-bd97-46a9-76ed-fab4f4c18400/public" alt=""><figcaption></figcaption></figure>

其实就和mufy页面上的\<message>一样的，气泡框样式是官方指定的。

正则就是一个自由工具，**你可以自定义自己的“\<message>”，它可以是地图，是状态栏，是小手机...**

***

#### **工具模式和通用模式的区别？**

无论选哪种，本质都是在创建一套“替换规则”区别在于：

* **工具模式（自动挡）：** 界面为你规定了标准用法，系统会**自动帮你生成**复杂的正则表达式。**优点：** 简单、规范、不容易出错。适合新手，简单场景。
* **通用模式（手动挡）：** 没有限制。需要自己（或求助 AI）**手动输入**正则表达式。**优点：** 极其自由，能实现复杂的操控。适合老手，复杂场景。

***

#### **如何教会AI输出？**

**采用我们推荐的格式编写AI输出** AI天生可以理解以下格式，输出更稳定

```xml
<EnvironmentData>
    <Time>13:37:33</Time>
    <Weather>多云转小雨</Weather>
    <Description>空气中飘着柳絮伴随着樱花香，春天到了</Description>
</EnvironmentData>
```

**编写输出设定** 在输出设定处，编写该何时输出，输出规则是什么

```
在每次对话开始时，按照剧情需要更新的环境信息，请严格按照以下XML结构输出环境数据组件。

<EnvironmentData>
    <Time>当前场景的具体时间</Time>
    <Weather>当前场景的天气情况</Weather>
    <Description>用一句话描述当前环境的氛围、气味或景象</Description>
</EnvironmentData>

【字段说明】
- <Time>：输出当前场景的具体时间，格式为 HH:MM:SS。
- <Weather>：简要描述当前的天气，如“晴朗”、“小雨”、“阴天有风”。
- <Description>：用一句带有感官细节的文字描述环境特色，例如“空气中弥漫着雨后泥土的清新气味”或“午后的阳光透过百叶窗，在木地板上投下斑驳的光影”。

【重要约束】
- 只输出上述XML结构，不要有任何开场白、解释或其他文字。
- 必须保持XML标签名称（EnvironmentData, Time, Weather, Description）完全一致，不要修改。
- 每个标签内只填写对应的内容，不要包含标签本身。
```

推荐将AI输出格式放入“开场设计”，AI将更加遵从

[查看更多详情](/documentation/zheng-ze-xiang-qing/ai-wen-ding-shu-chu-zheng-ze.md)

***

#### **原来的代码如何改成正则？**

如以下例子

<details>

<summary><mark style="color:$primary;">代码过长，点击展开/收起</mark></summary>

<pre class="language-html"><code class="lang-html"><strong>在每次对话开始时，输出环境数据栏目
</strong><strong>```html
</strong>&#x3C;!DOCTYPE html>
&#x3C;html lang="zh-CN">
&#x3C;head>
    &#x3C;meta charset="UTF-8">
    &#x3C;meta name="viewport" content="width=device-width, initial-scale=1.0">
    &#x3C;title>Midnight Gummy Ultra Panel&#x3C;/title>
    &#x3C;link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@500&#x26;family=Quicksand:wght@500;700&#x26;family=Noto+Sans+SC:wght@300;500&#x26;display=swap" rel="stylesheet">
    &#x3C;style>
        :root {
            --accent-pink: #ff9eaf;
            --accent-purple: #bb9af7;
            --accent-blue: #7dcfff;
            --text-main: #c0caf5;
            --text-dim: #565f89;
            --glass-bg: rgba(26, 27, 38, 0.6);
            --radius-main: 10px;
            --font-cute: 'Quicksand', 'Noto Sans SC', sans-serif;
            --font-mono: 'JetBrains Mono', monospace;
        }

        body {
            background: transparent;
            margin: 0;
        }

        /* 整体容器 */
        .ultra-panel {
            font-family: var(--font-cute);
            display: flex;
            flex-direction: column;
            gap: 12px;
            width:100%;
            max-width: 500px;
            user-select: none;
            position: relative;
        }

        .panel-row {
            display: flex;
            gap: 12px;
            width: 100%;
        }

        /* 基础项：玻璃拟态 + 复合阴影 */
        .data-card {
            background: var(--glass-bg);
            backdrop-filter: blur(12px);
            border: 1px solid rgba(255, 255, 255, 0.08);
            border-top: 1px solid rgba(255, 255, 255, 0.15); /* 顶部高光边 */
            border-radius: var(--radius-main);
            padding: 10px 14px;
            box-shadow: 
                4px 4px 0px rgba(0, 0, 0, 0.3),
                inset 0 1px 1px rgba(255, 255, 255, 0.05);
            display: flex;
            flex-direction: column;
            justify-content: center;
            position: relative;
            overflow: hidden;
            transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
        }

        /* 扫描线背景效果 */
        .data-card::before {
            content: "";
            position: absolute;
            top: 0; left: 0; right: 0; bottom: 0;
            background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.1) 50%), 
                        linear-gradient(90deg, rgba(255, 0, 0, 0.02), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.02));
            background-size: 100% 2px, 3px 100%;
            pointer-events: none;
            opacity: 0.3;
        }

        .data-card:hover {
            transform: translateY(-3px);
            background: rgba(30, 33, 48, 0.8);
            border-color: rgba(255, 255, 255, 0.2);
        }

        /* 装饰支架 */
        .corner-deco {
            position: absolute;
            width: 6px;
            height: 6px;
            border: 1px solid currentColor;
            opacity: 0.4;
        }
        .lt { top: 4px; left: 4px; border-right: 0; border-bottom: 0; }
        .rb { bottom: 4px; right: 4px; border-left: 0; border-top: 0; }

        /* 内容布局 */
        .card-header {
            display: flex;
            align-items: center;
            margin-bottom: 4px;
        }

        .label {
            font-size: 9px;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 1.5px;
            color: var(--text-dim);
        }

        .icon-svg {
            width: 12px;
            height: 12px;
            margin-right: 6px;
            fill: currentColor;
            filter: drop-shadow(0 0 3px currentColor);
        }

        .value {
            font-size: 13px;
            font-weight: 500;
            color: var(--text-main);
            display: flex;
            align-items: baseline;
        }

        /* 特殊样式 */
        .item-time { flex: 1.3; border-bottom: 2px solid var(--accent-purple); color: var(--accent-purple); }
        .item-weather { flex: 1; border-bottom: 2px solid var(--accent-blue); color: var(--accent-blue); }
        .item-env { width: 100%; border-bottom: 2px solid var(--accent-pink); color: var(--accent-pink); }

        /* 时间数值：等宽字体 */
        #current-time {
            font-family: var(--font-mono);
            font-size: 15px;
            letter-spacing: -0.5px;
        }

        /* 环境描述：稍微缩小 */
        .env-text {
            font-size: 11px;
            line-height: 1.4;
            opacity: 0.85;
        }

        /* 呼吸灯 */
        .status-dot {
            width: 3px;
            height: 3px;
            background: currentColor;
            border-radius: 50%;
            margin-left: auto;
            box-shadow: 0 0 6px currentColor;
            animation: blink 2s infinite;
        }

        @keyframes blink {
            0%, 100% { opacity: 1; transform: scale(1); }
            50% { opacity: 0.3; transform: scale(0.8); }
        }
    &#x3C;/style>
&#x3C;/head>
&#x3C;body>

    &#x3C;div class="ultra-panel">
        &#x3C;!-- 第一行 -->
        &#x3C;div class="panel-row">
            &#x3C;!-- 时间卡片 -->
            &#x3C;div class="data-card item-time">
                &#x3C;div class="corner-deco lt">&#x3C;/div>
                &#x3C;div class="corner-deco rb">&#x3C;/div>
                &#x3C;div class="card-header">
                    &#x3C;svg class="icon-svg" viewBox="0 0 24 24">&#x3C;path d="M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10 10-4.5 10-10S17.5 2 12 2zm0 18c-4.4 0-8-3.6-8-8s3.6-8 8-8 8 3.6 8 8-3.6 8-8 8zm.5-13H11v6l5.2 3.1.8-1.2-4.5-2.7V7z"/>&#x3C;/svg>
                    &#x3C;span class="label">Chrono&#x3C;/span>
                    &#x3C;div class="status-dot">&#x3C;/div>
                &#x3C;/div>
                &#x3C;div class="value">
                    &#x3C;span id="current-time">时间部分&#x3C;/span>
                &#x3C;/div>
            &#x3C;/div>

            &#x3C;!-- 天气卡片 -->
            &#x3C;div class="data-card item-weather">
                &#x3C;div class="corner-deco lt">&#x3C;/div>
                &#x3C;div class="corner-deco rb">&#x3C;/div>
                &#x3C;div class="card-header">
                    &#x3C;svg class="icon-svg" viewBox="0 0 24 24">&#x3C;path d="M6.7 14.7c0-3.1 2.5-5.7 5.7-5.7.3 0 .5 0 .8.1C14.1 6.8 16.4 5 19 5c3.3 0 6 2.7 6 6 0 .5-.1 1-.2 1.4 1.4.9 2.2 2.4 2.2 4.1 0 2.8-2.2 5-5 5h-13c-4 0-7.3-3.3-7.3-7.3 0-3.5 2.5-6.4 5.8-7.1.1-.1.2-.1.2-.4z"/>&#x3C;/svg>
                    &#x3C;span class="label">Sky&#x3C;/span>
                &#x3C;/div>
                &#x3C;div class="value">
                    &#x3C;span>今日天气&#x3C;/span>
                &#x3C;/div>
            &#x3C;/div>
        &#x3C;/div>

        &#x3C;!-- 第二行 -->
        &#x3C;div class="panel-row">
            &#x3C;!-- 环境描述卡片 -->
            &#x3C;div class="data-card item-env">
                &#x3C;div class="corner-deco lt">&#x3C;/div>
                &#x3C;div class="corner-deco rb">&#x3C;/div>
                &#x3C;div class="card-header">
                    &#x3C;svg class="icon-svg" viewBox="0 0 24 24">&#x3C;path d="M12 3L2 12h3v8h14v-8h3L12 3zm0 14.5c-1.4 0-2.5-1.1-2.5-2.5s2.5-4.5 2.5-4.5 2.5 3.1 2.5 4.5-1.1 2.5-2.5 2.5z"/>&#x3C;/svg>
                    &#x3C;span class="label">Atmosphere&#x3C;/span>
                    &#x3C;div class="status-dot">&#x3C;/div>
                &#x3C;/div>
                &#x3C;div class="value env-text">
                    环境描述内容
                &#x3C;/div>
            &#x3C;/div>
        &#x3C;/div>
    &#x3C;/div>
&#x3C;/body>
&#x3C;/html>
```
</code></pre>

</details>

**方案一：**

可以直接使用[AI一键生成指令](/documentation/guan-yu-zheng-ze/ai-yi-jian-sheng-cheng-zhi-ling.md)，让AI帮你改写，你可以这样告诉AI指令：

```
这是我原来的AI输出对话美化代码，请你帮我优化成正则的格式
```

**方案二：**

**也可以自己将代码进行拆分：**

1. 代码需要哪些动态数据，例如上方例子中的，时间/天气/当前氛围
2. 则AI输出的**目标字符**可以这样设计，按照[**官方支持模版**](/documentation/zheng-ze-xiang-qing/chuang-jian-zheng-ze-tiao-mu/shi-yong-dai-ma-zu-jian.md#guan-fang-zhi-chi-mo-ban)

```xml
<EnvironmentData>
    <Time>13:37:33</Time>
    <Weather>多云转小雨</Weather>
    <Description>空气中飘着柳絮伴随着樱花香，春天到了</Description>
</EnvironmentData>
```

3. 创建正则，使用工具模式/代码组件模式。将上方AI输出，填入**目标字符**中。将原来的代码填入，**替换字符串。**
4. 系统将自动生成正则表达式，系统提供以下映射：

`$1` ➡️  `13:37:33`

`$2` ➡️  `多云转小雨`

`$3` ➡️  `空气中飘着柳絮伴随着樱花香，春天到了`

5. 最后将变量映射的内容回填如替换字符串即可。

详细创建过程[使用代码组件](/documentation/zheng-ze-xiang-qing/chuang-jian-zheng-ze-tiao-mu/shi-yong-dai-ma-zu-jian.md)

#### AI输出正则总是不稳定？

使用**高级双子座2.5**用作正则输出时，常常会出现以下问题：

* 输出标签中经常会带有“-”符号，例如<状态栏>\</-状态栏>
* 输出的标签经常“有头没有尾”、“有尾没有头”
* 少输出一段标签
* 多输出一段标签

可以通过以下几个方面进行解决：

1. 使用英文作为标签名称，例如采用\<StatusBar>\</StatusBar>而非“状态栏”
2. 增强“输出设定”的AI输出约束，例如以下指令

```
【重要约束】
- 必须每次输出此XML结构。
- 保持标签名称（<状态栏>, <好感度>, <神态>, <心理活动>）完全一致，不要修改。
- 输出的XML结构前后不要添加任何解释或额外文字。
```

3. 我们推荐使用官方“[AI一键生成指令](/documentation/guan-yu-zheng-ze/ai-yi-jian-sheng-cheng-zhi-ling.md)”生成“目标字符”、“输出约束”
4.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mufy.ai/documentation/guan-yu-zheng-ze/chang-jian-wen-ti.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
