%% 正则解析与匹配结果对比流程
flowchart TD
Start["🔹 开始"] --> Step1_1["1.1 拆分regex结构
(通过特殊的正则表达式,匹配目标regex,将其分解为比例为1:1:1:1+的如下结构:
▫️前 缀:实际匹配字符、定位点、分组构造前缀[(、(?>、(?=等]、内联注释、右括号')'、'|'
▫️量词1:+、*、?、{num1,num2}等基础量词
▫️量词2:惰性匹配符号'?'
▫️注 释:内联注释、行尾注释、无效空格(至少含1个空注释作为间隔)
"]
Step1_1 --> Step1_2["1.2 解析为自定义语法树
(遍历所有分解结构,生成结构化语法树)
可能会执行以下操作:
▫️简化量词
▫️移动被忽略空格、内联注释、行尾注释后的量词
▫️简化条件表达式中多余的'|'
▫️全平台兼容转换(参考:
全平台兼容issue)
"]
Step1_2 --> Step_input{"是否有input需要匹配?"}
Step_input --> |是| Step2["2. 初始化输入下标
(设置txtpos = 0)"]
Step_input --> |否| Step9["9. 返回压缩后的结果"]
Step2 --> Step3["3. 推理新匹配项
(从txtpos位置开始推理正则匹配项)"]
Step3 --> Step4{"4. 匹配是否成功?"}
Step4 -->|成功| Step5["5. 结果对比校验
(与C#正则引擎输出对比所有组的捕获Index和Length)
(
为什么需要两种验证模式?因为有时候两个模式输出不一致)"]
Step5 --> Step6{"6. 当前匹配长度是否为0?"}
Step6 -->|是| Step6a["txtpos += 1
(避免无限循环)"]
Step6 -->|否| Step6b["txtpos = 当前匹配项结束位置"]
Step6a & Step6b --> Step7{"7. txtpos 是否到达input末尾?"}
Step7 -->|否| Step3
Step7 -->|是| Step8["8. 匹配项数一致性校验
(对比推理匹配项数与C#输出项数,不一致则标记)"]
Step4 -->|失败| Step8
Step8 --> Step9
Step9 --> End["🔹 结束"]
%% 样式定义(与示例完全一致)
classDef startEnd fill:#f0f8ff,stroke:#1976d2,stroke-width:2px,rounded:10px
classDef process fill:#e8f5e9,stroke:#388e3c,stroke-width:1.5px,rounded:5px
classDef decision fill:#fff3e0,stroke:#f57c00,stroke-width:1.5px,diamond:true
%% 样式绑定(与示例完全一致)
class Start,End startEnd
class Step1_1,Step1_2,Step2,Step3,Step5,Step6a,Step6b,Step8,Step9 process
class Step_input,Step4,Step6,Step7 decision