SKILL

regex-vs-llm-structured-text

Decision framework for choosing between regex and large language models when parsing structured text—start with regex and add large language models only for low-confidence edge cases.

Translation reviewed
Read the original Chinese text

选择在解析结构化文本时使用正则表达式还是大型语言模型的决策框架——从正则表达式开始,仅在低置信度的边缘情况下添加大型语言模型。

Target: AI & workflow automation. Automatically collected · unverified.

Excerpt from the author’s documentation

Extracted from a fixed version of SKILL.md in its original language. This is the author’s documentation; installation, compatibility and runtime results have not been verified by this site.

Read the original Chinese text

Topics in the source

  • 正则表达式 vs LLM 用于结构化文本解析
  • 何时使用
  • 决策框架
  • 架构模式
  • 实现
  • 1. 正则表达式解析器(处理大多数情况)
  • 2. 置信度评分
  • 3. LLM 验证器(仅用于边缘情况)

一个用于解析结构化文本(测验、表单、发票、文档)的实用决策框架。核心见解是:正则表达式能以低成本、确定性的方式处理 95-98% 的情况。将昂贵的 LLM 调用留给剩余的边缘情况。 解析具有重复模式的结构化文本(问题、表单、表格) 决定在文本提取时使用正则表达式还是 LLM 构建结合两种方法的混合管道 在文本处理中优化成本/准确性权衡 标记可能需要 LLM 审核的项: 来自一个生产中的测验解析管道(410 个项目): | 指标 | 值 | |--------|-------| | 正则表达式成功率 | 98.0% | | 低置信度项目 | 8 (2.0%) | | 所需 LLM 调用次数 | 5 | | 相比全 LLM 的成本节省 | 95% | | 测试覆盖率 | 93% | 从正则表达式开始 — 即使不完美的正则表达式也能提供一个改进的基线 使用置信度评分 来以编程方式识别需要 LLM 帮助的内容 使用最便宜的 LLM 进行验证(Haiku 类模型已足够) 切勿修改 已解析的项 — 从清理/验证步骤返回新实例 TDD 效果很好 用于解析器 — 首先为已知模式编写测试,然后是边缘情况 记录指标(正则表达式成功率、LLM 调用次数)以跟踪管道健康状况 当正则表达式能处理 95% 以上的情况时,将所有文本发送给 LLM(昂贵且缓慢) 对自由格式、高度可变的文本使用正则表达式(LLM 在此处更合适) 跳过置信度评分,希望正则表达式“能正常工作” 在清理/验证步骤中修改已解析的对象 不测试边缘情况(格式错误的输入、缺失字段、编码问题) 测验/考试题目解析 表单数据提取 发票/收据处理 文档结构解析(标题、章节、表格) 任何具有重复模式且成本重要的结构化文本

Source repository
affaan-m/ECC
Source file
docs/zh-CN/skills/regex-vs-llm-structured-text/SKILL.md
Fixed revision
d2ef2680594f9a17526a6e1a2e18b3d242c5d17b
Read the complete original documentation ↗

Sources and evidence

This record was collected automatically. Its documentation, suitability and runtime behavior have not been manually verified.

Author: affaan-m/ECC · original repository metadata. Documentation review: Not reviewed. Last source check: 2026-11-09T15:01:42.555Z.

Categories are inferred from names, descriptions and paths. They do not establish compatibility.

License and attribution

MIT. Third-party content and copyright remain with their authors. Refer to the original license and terms.

Original license ↗

Synchronization, copying and user-reported success do not mark a resource as runtime-tested.

Limitations and notes

  • Collecting metadata does not mean this site has installed, adapted, runtime-tested or security-reviewed the resource.